> ## Documentation Index
> Fetch the complete documentation index at: https://docs.stateset.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Create or replace a macro.

> **Required scope:** write

**Required scope:** `write`

### Request body

`CreateMacroRequest`

<ParamField body="auto_send" type="boolean" />

<ParamField body="body" type="string" required>
  The text sent to the customer. `&#123;&#123;slot&#125;&#125;` marks a merge field.
</ParamField>

<ParamField body="channel" type="string" />

<ParamField body="name" type="string" required>
  Unique within the org. Re-posting a name REPLACES that macro.
</ParamField>

<ParamField body="rule_name" type="string" />

<ParamField body="source" type="string" />

<ParamField body="status" type="object" />

<ParamField body="tags" type="string[]" />

<ParamField body="title" type="string" />

<ParamField body="tool" type="object" />

### Response

`Macro`

<ResponseField name="auto_send" type="boolean" required />

<ResponseField name="body" type="string" required />

<ResponseField name="channel" type="string" />

<ResponseField name="created_at" type="string" required />

<ResponseField name="id" type="string" required />

<ResponseField name="name" type="string" required>
  Upsert key within an org, matching the rules convention.
</ResponseField>

<ResponseField name="org_id" type="string" required />

<ResponseField name="rule_name" type="string">
  The policy rule whose citation selects this macro.
</ResponseField>

<ResponseField name="slots" type="string[]" required>
  Merge fields parsed from `body` at write time.
</ResponseField>

<ResponseField name="source" type="string" />

<ResponseField name="status" type="MacroStatus" required />

<ResponseField name="tags" type="string[]" />

<ResponseField name="title" type="string" />

<ResponseField name="tool" type="object">
  <Expandable title="tool">
    <ResponseField name="arguments" type="object" />

    <ResponseField name="name" type="string" required />
  </Expandable>
</ResponseField>

<ResponseField name="updated_at" type="string" required />

### Status codes

| Code  | Meaning                                             |
| ----- | --------------------------------------------------- |
| `201` | Macro created or replaced                           |
| `400` | Invalid macro (empty body, unbalanced merge fields) |
| `401` | Unauthorized — missing or invalid credentials       |
| `403` | Forbidden — the key/token lacks the required scope  |
| `429` | Rate limited — see Retry-After / X-RateLimit-Reset  |

<RequestExample>
  ```bash cURL theme={null}
  curl --request POST \
    --url 'https://api.nsr.stateset.com/api/v1/macros' \
    --header 'X-API-Key: YOUR_API_KEY' \
    --header 'Content-Type: application/json' \
    --data '{
    "auto_send": true,
    "body": "Two-person tent, green — replacement for damaged pole set.",
    "channel": "string",
    "name": "Two-Person Tent",
    "rule_name": "string",
    "source": "string",
    "status": {
      "0": "c",
      "1": "a",
      "2": "n",
      "3": "d",
      "4": "i",
      "5": "d",
      "6": "a",
      "7": "t",
      "8": "e"
    },
    "tags": [
      "priority"
    ],
    "title": "Replacement tent pole set",
    "tool": {
      "arguments": {},
      "name": "Two-Person Tent"
    }
  }'
  ```
</RequestExample>

<ResponseExample>
  ```json 201 theme={null}
  {
    "auto_send": true,
    "body": "Two-person tent, green — replacement for damaged pole set.",
    "channel": "string",
    "created_at": "2026-08-31T14:22:05Z",
    "id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "name": "Two-Person Tent",
    "org_id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
    "rule_name": "string",
    "slots": [
      "string"
    ],
    "source": "string",
    "status": "candidate",
    "tags": [
      "priority"
    ],
    "title": "Replacement tent pole set",
    "tool": {
      "arguments": {},
      "name": "Two-Person Tent"
    },
    "updated_at": "2026-08-31T14:22:05Z"
  }
  ```
</ResponseExample>
