---
title: "Upsert logic rule by external rule_id"
method: POST
path: "/api/logic/rules/upsert"
tags: ["Logic Engine"]
---

# Upsert logic rule by external rule_id

`POST /api/logic/rules/upsert`

## Request

- Base URL: `https://api.agentstack.tech` (the document declares no server; this is the origin it was published from)
- URL: `https://api.agentstack.tech/api/logic/rules/upsert`
- Auth: one of:
  - API key in header `X-API-Key`
  - HTTP bearer

Create or update a logic rule keyed by stable ``rule_id`` (``external_rule_key``).

CardGame templates and deploy scripts send ``steps`` instead of ``space``;
saga/auth/compensate/metadata are stored in ``editor_metadata``.

## Headers

- `Idempotency-Key` string

## Request body

- UpsertLogicRuleRequest: Flexible body for idempotent rule upsert keyed by ``rule_id``.
  - `rule_id` string, required
  - `name` string, nullable
  - `description` string, nullable
  - `triggers` object[], nullable
  - `schedulers` object[], nullable
  - `space` object[], nullable
  - `steps` object[], nullable
  - `saga` object, nullable
  - `auth` object, nullable
  - `compensate` object[], nullable
  - `metadata` object, nullable
  - `editor_metadata` object, nullable
  - `enabled` boolean, nullable
  - `priority` integer, nullable
  - `project_id` integer, nullable
  - `path_updates` object, nullable

## Response `200`

Successful Response

- unknown

## Other responses

- `400`: Bad Request
- `401`: Unauthorized
- `403`: Forbidden
- `404`: Not Found
- `409`: Conflict
- `422`: Validation Error
- `429`: Too Many Requests
- `500`: Internal Server Error

---

[API](https://skmtc.dev/agentstack/apis/agentstack-core-api.md) · [All operations](https://skmtc.dev/agentstack/apis/agentstack-core-api/llms.txt) · [OpenAPI document](https://skmtc.dev/agentstack/apis/agentstack-core-api/revisions/79f4a4dd8813?raw)
