# message_history.list

Histórico de envio: mensagens enviadas. Aba Mensagens do Histórico de envio: cada mensagem enviada (atendente, automação, disparo em massa ou o celular), da mais recente, com `status` (queued, sent, delivered, visualized, failed; `sending` não existe aqui e filtra para vazio), `messagePlatform` (whatsapp, evolution, instagram), `lead` e `channel` (endereço do destinatário), `messageService` (`workflows`, `broadcast` ou `individual`), `error`. Filtros: `search` (nome, e-mail ou telefone do contato, ou o texto), `status`, `platform`, `broadcastIds` (envios de `broadcasts.list`), `workflowIds` (automações), `from`/`to` e `leadId`. `webhookLogsCount` é sempre 0 e `creditCost` nulo: o Atomiks não guarda os dois por mensagem. Automação vem de `sent_by` nulo; o filtro por automação considera as conversas em que ela rodou.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `search` | string | não |  |
| `status` | "queued" \| "sending" \| "sent" \| "delivered" \| "failed" \| "visualized" | não |  |
| `platform` | string | não |  |
| `broadcastIds` | string (uuid)[] | não |  |
| `workflowIds` | string (uuid)[] | não |  |
| `from` | string | não |  |
| `to` | string | não |  |
| `leadId` | string (uuid) | não |  |
| `page` | integer | não | padrão 1 |
| `perPage` | integer | não | padrão 20 |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "search": {
      "type": "string",
      "maxLength": 120
    },
    "status": {
      "type": "string",
      "enum": [
        "queued",
        "sending",
        "sent",
        "delivered",
        "failed",
        "visualized"
      ]
    },
    "platform": {
      "type": "string",
      "maxLength": 40
    },
    "broadcastIds": {
      "maxItems": 50,
      "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)$"
      }
    },
    "workflowIds": {
      "maxItems": 50,
      "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)$"
      }
    },
    "from": {
      "type": "string",
      "maxLength": 40
    },
    "to": {
      "type": "string",
      "maxLength": 40
    },
    "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": {
      "default": 1,
      "type": "integer",
      "minimum": 1,
      "maximum": 10000
    },
    "perPage": {
      "default": 20,
      "type": "integer",
      "minimum": 1,
      "maximum": 100
    }
  }
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/message_history.list \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"page":1,"perPage":20}'
```

CLI:

```bash
node cli/atomiks.mjs message_history.list --json '{"page":1,"perPage":20}'
```

MCP: ferramenta `message_history_list` 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": {
          "id": {
            "type": "string"
          },
          "queuedAt": {
            "type": "string"
          },
          "messagePlatform": {
            "type": "string"
          },
          "status": {
            "type": "string",
            "enum": [
              "queued",
              "sending",
              "sent",
              "delivered",
              "failed",
              "visualized"
            ]
          },
          "webhookLogsCount": {
            "type": "number"
          },
          "error": {
            "type": [
              "string",
              "null"
            ]
          },
          "leadId": {
            "type": "string"
          },
          "lead": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "name": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "email": {
                    "type": [
                      "string",
                      "null"
                    ]
                  },
                  "telephone": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "name",
                  "email",
                  "telephone"
                ],
                "additionalProperties": false
              },
              {
                "type": "null"
              }
            ]
          },
          "channel": {
            "type": [
              "string",
              "null"
            ]
          },
          "messageService": {
            "type": "string",
            "enum": [
              "workflows",
              "broadcast",
              "individual"
            ]
          },
          "creditCost": {
            "type": [
              "number",
              "null"
            ]
          },
          "messageName": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "queuedAt",
          "messagePlatform",
          "status",
          "webhookLogsCount",
          "error",
          "leadId",
          "lead",
          "channel",
          "messageService",
          "creditCost",
          "messageName"
        ],
        "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).
