# automations.runs

Histórico de execuções das automações. Execuções do mais recente para o mais antigo. Filtros: `automationId`, `status`. Use `before` (o `nextBefore` anterior) para a página seguinte.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `automationId` | string (uuid) | não |  |
| `status` | "pending" \| "sending" \| "done" \| "failed" \| "skipped" | não |  |
| `limit` | integer | não | padrão 50 |
| `before` | string | não |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "automationId": {
      "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)$"
    },
    "status": {
      "type": "string",
      "enum": [
        "pending",
        "sending",
        "done",
        "failed",
        "skipped"
      ]
    },
    "limit": {
      "default": 50,
      "type": "integer",
      "minimum": 1,
      "maximum": 100
    },
    "before": {
      "type": "string"
    }
  }
}
```

</details>

## Exemplo

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

CLI:

```bash
node cli/atomiks.mjs automations.runs --json '{"limit":50}'
```

MCP: ferramenta `automations_runs` 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": {
    "items": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "automationId": {
            "type": "string"
          },
          "automationName": {
            "type": [
              "string",
              "null"
            ]
          },
          "status": {
            "type": "string",
            "enum": [
              "pending",
              "sending",
              "done",
              "failed",
              "skipped"
            ]
          },
          "igUserId": {
            "type": "string"
          },
          "contact": {
            "anyOf": [
              {
                "type": "object",
                "properties": {
                  "id": {
                    "type": "string"
                  },
                  "name": {
                    "type": [
                      "string",
                      "null"
                    ]
                  }
                },
                "required": [
                  "id",
                  "name"
                ],
                "additionalProperties": false
              },
              {
                "type": "null"
              }
            ]
          },
          "commentId": {
            "type": [
              "string",
              "null"
            ]
          },
          "mediaId": {
            "type": [
              "string",
              "null"
            ]
          },
          "attempts": {
            "type": "number"
          },
          "lastError": {
            "type": [
              "string",
              "null"
            ]
          },
          "publicReplyId": {
            "type": [
              "string",
              "null"
            ]
          },
          "dmMessageId": {
            "type": [
              "string",
              "null"
            ]
          },
          "createdAt": {
            "type": "string"
          },
          "doneAt": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "id",
          "automationId",
          "automationName",
          "status",
          "igUserId",
          "contact",
          "commentId",
          "mediaId",
          "attempts",
          "lastError",
          "publicReplyId",
          "dmMessageId",
          "createdAt",
          "doneAt"
        ],
        "additionalProperties": false
      }
    },
    "nextBefore": {
      "type": [
        "string",
        "null"
      ]
    }
  },
  "required": [
    "items",
    "nextBefore"
  ],
  "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).
