# message_history.export

Exportar o histórico de envio em CSV. CSV com uma mensagem por linha das que batem com os filtros de `message_history.list` (até 5 000, as mais recentes): ID, data e hora (fuso de São Paulo), canal, status, erro, destinatário, endereço, categoria de envio e custo de créditos. Devolve `filename`, `csv` (texto) e `count`.

- Endpoint: `POST https://app.atomiks.com.br/api/v1/message_history.export` (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_export`
- Ficha em JSON: `https://app.atomiks.com.br/api/v1/openapi.json` (operationId `message_history.export`)

## 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 |  |

<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)$"
    }
  }
}
```

</details>

## Exemplo

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

CLI:

```bash
node cli/atomiks.mjs message_history.export --json '{}'
```

MCP: ferramenta `message_history_export` 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": {
    "filename": {
      "type": "string"
    },
    "csv": {
      "type": "string"
    },
    "count": {
      "type": "number"
    }
  },
  "required": [
    "filename",
    "csv",
    "count"
  ],
  "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).
