# contacts.bulk_enroll_flow

Colocar vários contatos num flow. `target` é `{ids}` (contatos escolhidos) ou `{filter, q?, excludeIds?}` ("todos os que casam", mesmo filtro e busca de `contacts.list`); só entram contatos que o membro vê, até 10 000. `flowId` é um flow ativo (publicado e ligado; veja `flows.list` com `status: "active"`). Cada contato começa uma execução da versão publicada, como em `flows.test_run`, ignorando os gatilhos de início; o worker roda as execuções em segundo plano. Quem já está no flow fica onde está e conta em `skipped`.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `target` | object | sim |  |
| `flowId` | string (uuid) | sim |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "target": {
      "anyOf": [
        {
          "type": "object",
          "properties": {
            "ids": {
              "minItems": 1,
              "maxItems": 10000,
              "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)$"
              }
            }
          },
          "required": [
            "ids"
          ],
          "additionalProperties": false
        },
        {
          "type": "object",
          "properties": {
            "filter": {
              "maxItems": 200,
              "type": "array",
              "items": {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string",
                    "maxLength": 64
                  },
                  "order": {
                    "type": "integer",
                    "minimum": 0,
                    "maximum": 1000
                  },
                  "field": {
                    "type": "string",
                    "maxLength": 60
                  },
                  "operator": {
                    "type": "string",
                    "maxLength": 30
                  },
                  "negation": {
                    "default": false,
                    "type": "boolean"
                  },
                  "parentId": {
                    "anyOf": [
                      {
                        "type": "string",
                        "maxLength": 64
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "valueString": {
                    "anyOf": [
                      {
                        "type": "string",
                        "maxLength": 4000
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "valueNumber": {
                    "type": [
                      "number",
                      "null"
                    ]
                  },
                  "valueDate": {
                    "anyOf": [
                      {
                        "type": "string",
                        "maxLength": 40
                      },
                      {
                        "type": "null"
                      }
                    ]
                  },
                  "valueBool": {
                    "type": [
                      "boolean",
                      "null"
                    ]
                  },
                  "valueUuid": {
                    "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": [
                  "field",
                  "operator"
                ],
                "additionalProperties": false
              }
            },
            "q": {
              "type": "string",
              "maxLength": 100
            },
            "excludeIds": {
              "maxItems": 10000,
              "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)$"
              }
            }
          },
          "required": [
            "filter"
          ],
          "additionalProperties": false
        }
      ]
    },
    "flowId": {
      "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)$"
    }
  },
  "required": [
    "target",
    "flowId"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/contacts.bulk_enroll_flow \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"target":{"ids":["00000000-0000-0000-0000-000000000000"]},"flowId":"00000000-0000-0000-0000-000000000000"}'
```

CLI:

```bash
node cli/atomiks.mjs contacts.bulk_enroll_flow --json '{"target":{"ids":["00000000-0000-0000-0000-000000000000"]},"flowId":"00000000-0000-0000-0000-000000000000"}'
```

MCP: ferramenta `contacts_bulk_enroll_flow` 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": {
    "count": {
      "type": "number"
    },
    "skipped": {
      "type": "number"
    }
  },
  "required": [
    "count",
    "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).
