# activities.message_thread

Mensagens enviadas a um contato. Mensagens enviadas ao contato (mais recente primeiro), uma por item: `instanceId` (id da mensagem), `platform`, `status` (queued, sent, delivered, visualized, failed), `queuedAt`, `contents` ([{id, order, format, content, fileName, caption}]) e `error`. `emailSubject`, `messageName` e `creditCost` existem no original e ficam `null`. O contato precisa estar visível (`not_found` se não). Página de 200 por padrão, até 500.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `leadId` | string (uuid) | sim |  |
| `page` | integer | não |  |
| `perPage` | integer | não |  |
| `platform` | string | não |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "leadId": {
      "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)$"
    },
    "page": {
      "type": "integer",
      "minimum": 1,
      "maximum": 10000
    },
    "perPage": {
      "type": "integer",
      "minimum": 1,
      "maximum": 500
    },
    "platform": {
      "type": "string",
      "maxLength": 40
    }
  },
  "required": [
    "leadId"
  ]
}
```

</details>

## Exemplo

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

CLI:

```bash
node cli/atomiks.mjs activities.message_thread --json '{"leadId":"00000000-0000-0000-0000-000000000000"}'
```

MCP: ferramenta `activities_message_thread` 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": {
    "data": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "instanceId": {
            "type": "string"
          },
          "platform": {
            "type": "string"
          },
          "status": {
            "type": "string"
          },
          "queuedAt": {
            "type": "string"
          },
          "contents": {
            "type": "array",
            "items": {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "order": {
                  "type": "number"
                },
                "format": {
                  "type": "string"
                },
                "content": {
                  "type": "string"
                },
                "fileName": {
                  "type": [
                    "string",
                    "null"
                  ]
                },
                "caption": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "id",
                "order",
                "format",
                "content",
                "fileName",
                "caption"
              ],
              "additionalProperties": false
            }
          },
          "emailSubject": {
            "type": "null"
          },
          "messageName": {
            "type": "null"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "creditCost": {
            "type": "null"
          }
        },
        "required": [
          "instanceId",
          "platform",
          "status",
          "queuedAt",
          "contents",
          "emailSubject",
          "messageName",
          "error",
          "creditCost"
        ],
        "additionalProperties": false
      }
    },
    "meta": {
      "type": "object",
      "properties": {
        "page": {
          "type": "number"
        },
        "perPage": {
          "type": "number"
        },
        "countItens": {
          "type": "number"
        },
        "countPages": {
          "type": "number"
        }
      },
      "required": [
        "page",
        "perPage",
        "countItens",
        "countPages"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "data",
    "meta"
  ],
  "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).
