# crm.opportunities_bulk_attendants

Atribuir atendentes a várias oportunidades. Troca os atendentes de várias oportunidades de uma vez (`POST /v2/opportunities/bulk-action/attendants` do original). Escolha as oportunidades por `cardIds` ou por `allMatching: true` com `scope` (`pipelineId`, `stageId` opcional e `filters` opcional com `status` e `attendantIds`, o responsável atual; outro filtro dá `invalid_input`). `assignments` leva um atendente por papel (`attendantTypeId`); o principal (`isPrimary`, ou o primeiro) vira o responsável (`owner_id`) da oportunidade e os outros ficam como atendentes por papel. Substitui os atendentes que a oportunidade tinha. Só atua em oportunidades que o chamador pode ver; as demais entram em `skipped`. Até 5000 por chamada, sempre síncrono (`mode: "sync"`, `jobId: null`). Exige a migration de disponibilidade (`migration_pendente` sem ela).

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `cardIds` | string (uuid)[] | não |  |
| `allMatching` | true | não |  |
| `scope` | object | não |  |
| `assignments` | object[] | sim |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "cardIds": {
      "minItems": 1,
      "maxItems": 5000,
      "type": "array",
      "items": {
        "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)$"
      }
    },
    "allMatching": {
      "type": "boolean",
      "const": true
    },
    "scope": {
      "type": "object",
      "properties": {
        "pipelineId": {
          "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": {
          "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)$"
        },
        "filters": {
          "type": "object",
          "properties": {
            "status": {
              "type": "string",
              "enum": [
                "open",
                "won",
                "lost"
              ]
            },
            "attendantIds": {
              "maxItems": 100,
              "type": "array",
              "items": {
                "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)$"
              }
            }
          },
          "additionalProperties": false
        }
      },
      "required": [
        "pipelineId"
      ]
    },
    "assignments": {
      "minItems": 1,
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "attendantId": {
            "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)$"
          },
          "attendantTypeId": {
            "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"
              }
            ]
          },
          "isPrimary": {
            "type": "boolean"
          }
        },
        "required": [
          "attendantId"
        ]
      }
    }
  },
  "required": [
    "assignments"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/crm.opportunities_bulk_attendants \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"cardIds":["00000000-0000-0000-0000-000000000000"],"assignments":[{"attendantId":"00000000-0000-0000-0000-000000000000","attendantTypeId":"00000000-0000-0000-0000-000000000000","isPrimary":true}]}'
```

CLI:

```bash
node cli/atomiks.mjs crm.opportunities_bulk_attendants --json '{"cardIds":["00000000-0000-0000-0000-000000000000"],"assignments":[{"attendantId":"00000000-0000-0000-0000-000000000000","attendantTypeId":"00000000-0000-0000-0000-000000000000","isPrimary":true}]}'
```

MCP: ferramenta `crm_opportunities_bulk_attendants` 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": {
    "mode": {
      "type": "string",
      "const": "sync"
    },
    "jobId": {
      "type": "null"
    },
    "affected": {
      "type": "number"
    },
    "skipped": {
      "type": "number"
    }
  },
  "required": [
    "mode",
    "jobId",
    "affected",
    "skipped"
  ],
  "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).
