# cadences.set_stage

Vincular cadência a uma etapa. A cadência passa a começar sozinha quando a oportunidade entra na etapa (`stageId`, etapa aberta). `null` desvincula (avulsa). Cada etapa tem uma cadência: a que já estava nela deixa de começar ali. Devolve a cadência.

- Endpoint: `POST https://app.atomiks.com.br/api/v1/cadences.set_stage` (corpo JSON)
- Quem pode chamar: administrador da conta
- Escopo da chave: `crm:write`
- Grava dados: sim
- Pela chave de API: sim
- Ferramenta MCP: `cadences_set_stage`
- Ficha em JSON: `https://app.atomiks.com.br/api/v1/openapi.json` (operationId `cadences.set_stage`)

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `id` | string (uuid) | sim |  |
| `stageId` | string (uuid) \| null | sim |  |

<details><summary>JSON Schema</summary>

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string",
      "format": "uuid",
      "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
    },
    "stageId": {
      "anyOf": [
        {
          "type": "string",
          "format": "uuid",
          "pattern": "^([0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[1-8][0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}|00000000-0000-0000-0000-000000000000|ffffffff-ffff-ffff-ffff-ffffffffffff)$"
        },
        {
          "type": "null"
        }
      ]
    }
  },
  "required": [
    "id",
    "stageId"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/cadences.set_stage \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"id":"00000000-0000-0000-0000-000000000000","stageId":"00000000-0000-0000-0000-000000000000"}'
```

CLI:

```bash
node cli/atomiks.mjs cadences.set_stage --json '{"id":"00000000-0000-0000-0000-000000000000","stageId":"00000000-0000-0000-0000-000000000000"}'
```

MCP: ferramenta `cadences_set_stage` com a mesma entrada.

## Saída

Sucesso: `{"data": ...}` com o formato abaixo.

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "description": {
      "type": [
        "string",
        "null"
      ]
    },
    "isActive": {
      "type": "boolean"
    },
    "stageId": {
      "type": [
        "string",
        "null"
      ]
    },
    "stageName": {
      "type": [
        "string",
        "null"
      ]
    },
    "businessHoursCalendarId": {
      "type": [
        "string",
        "null"
      ]
    },
    "dailyLimitPerAttendant": {
      "type": [
        "number",
        "null"
      ]
    },
    "phaseNames": {
      "type": "array",
      "items": {
        "type": "string"
      }
    },
    "steps": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "position": {
            "type": "number"
          },
          "phase": {
            "type": "number"
          },
          "type": {
            "type": "string",
            "enum": [
              "call",
              "whatsapp",
              "meeting",
              "task"
            ]
          },
          "priority": {
            "type": "string",
            "enum": [
              "none",
              "urgent",
              "high",
              "medium",
              "low"
            ]
          },
          "waitMinutes": {
            "type": "number"
          },
          "durationMinutes": {
            "type": [
              "number",
              "null"
            ]
          },
          "title": {
            "type": "string"
          },
          "description": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "position",
          "phase",
          "type",
          "priority",
          "waitMinutes",
          "durationMinutes",
          "title",
          "description"
        ],
        "additionalProperties": false
      }
    },
    "liveRuns": {
      "type": "number"
    },
    "createdAt": {
      "type": "string"
    },
    "updatedAt": {
      "type": "string"
    }
  },
  "required": [
    "id",
    "name",
    "description",
    "isActive",
    "stageId",
    "stageName",
    "businessHoursCalendarId",
    "dailyLimitPerAttendant",
    "phaseNames",
    "steps",
    "liveRuns",
    "createdAt",
    "updatedAt"
  ],
  "additionalProperties": false
}
```

## Erros

`{"error": {"code", "message", "requestId"}}`. Códigos: `invalid_input` (400), `unauthorized` (401), `forbidden` / `account_pending` / `scope_missing` (403), `not_found` (404), `limit_reached` (409), `internal` (500).
