# flows.stats

Números por passo do flow. Execuções do período (padrão: últimos 30 dias) da versão publicada, ou de `versionId`. `nodes[nodeId]`: `entered` = execuções distintas que passaram pelo nó, `handles` = quantas saíram por cada handle, `failed` = passos com falha. Lê até 20 000 execuções; acima disso `truncated` fica true e vale só para as mais recentes.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `flowId` | string (uuid) | sim |  |
| `from` | string (date-time) | não |  |
| `to` | string (date-time) | não |  |
| `versionId` | string (uuid) | não |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "flowId": {
      "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",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
    },
    "to": {
      "type": "string",
      "format": "date-time",
      "pattern": "^(?:(?:\\d\\d[2468][048]|\\d\\d[13579][26]|\\d\\d0[48]|[02468][048]00|[13579][26]00)-02-29|\\d{4}-(?:(?:0[13578]|1[02])-(?:0[1-9]|[12]\\d|3[01])|(?:0[469]|11)-(?:0[1-9]|[12]\\d|30)|(?:02)-(?:0[1-9]|1\\d|2[0-8])))T(?:(?:[01]\\d|2[0-3]):[0-5]\\d:[0-5]\\d(?:\\.\\d+)?(?:Z))$"
    },
    "versionId": {
      "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": [
    "flowId"
  ]
}
```

</details>

## Exemplo

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

CLI:

```bash
node cli/atomiks.mjs flows.stats --json '{"flowId":"00000000-0000-0000-0000-000000000000"}'
```

MCP: ferramenta `flows_stats` 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": {
    "total": {
      "type": "object",
      "properties": {
        "started": {
          "type": "number"
        },
        "completed": {
          "type": "number"
        },
        "failed": {
          "type": "number"
        },
        "live": {
          "type": "number"
        }
      },
      "required": [
        "started",
        "completed",
        "failed",
        "live"
      ],
      "additionalProperties": false
    },
    "nodes": {
      "type": "object",
      "propertyNames": {
        "type": "string"
      },
      "additionalProperties": {
        "type": "object",
        "properties": {
          "entered": {
            "type": "number"
          },
          "handles": {
            "type": "object",
            "propertyNames": {
              "type": "string"
            },
            "additionalProperties": {
              "type": "number"
            }
          },
          "failed": {
            "type": "number"
          }
        },
        "required": [
          "entered",
          "handles",
          "failed"
        ],
        "additionalProperties": false
      }
    },
    "truncated": {
      "type": "boolean"
    }
  },
  "required": [
    "total",
    "nodes",
    "truncated"
  ],
  "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).
