# message_history.detail

Detalhe de uma mensagem do histórico de envio. Detalhe da instância: a mensagem (`instance`, com os horários das etapas: fila, enviado, entregue, visualizado, falha; entregue e visualizado valem o horário da própria mensagem, o Atomiks não guarda o de cada etapa) e, na automação, `flow` (a mais recente que rodou na conversa até então); `messages` (outras mensagens enviadas ao mesmo contato, até 12), `webhookLogs` (sempre vazio) e `opportunities` (oportunidades abertas do contato).

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `id` | string (uuid) | sim |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "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": [
    "id"
  ]
}
```

</details>

## Exemplo

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

CLI:

```bash
node cli/atomiks.mjs message_history.detail --json '{"id":"00000000-0000-0000-0000-000000000000"}'
```

MCP: ferramenta `message_history_detail` 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": {
    "instance": {
      "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"
          ]
        },
        "sentAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "deliveredAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "visualizedAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "clickedAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "failedAt": {
          "type": [
            "string",
            "null"
          ]
        },
        "flow": {
          "anyOf": [
            {
              "type": "object",
              "properties": {
                "id": {
                  "type": "string"
                },
                "name": {
                  "type": [
                    "string",
                    "null"
                  ]
                }
              },
              "required": [
                "id",
                "name"
              ],
              "additionalProperties": false
            },
            {
              "type": "null"
            }
          ]
        }
      },
      "required": [
        "id",
        "queuedAt",
        "messagePlatform",
        "status",
        "webhookLogsCount",
        "error",
        "leadId",
        "lead",
        "channel",
        "messageService",
        "creditCost",
        "messageName",
        "sentAt",
        "deliveredAt",
        "visualizedAt",
        "clickedAt",
        "failedAt",
        "flow"
      ],
      "additionalProperties": false
    },
    "messages": {
      "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
      }
    },
    "webhookLogs": {
      "type": "array",
      "items": {}
    },
    "opportunities": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": [
              "string",
              "null"
            ]
          },
          "pipelineId": {
            "type": "string"
          },
          "pipelineName": {
            "type": [
              "string",
              "null"
            ]
          },
          "stageName": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "title",
          "pipelineId",
          "pipelineName",
          "stageName"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "instance",
    "messages",
    "webhookLogs",
    "opportunities"
  ],
  "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).
