# crm.pipelines_overview

Visão geral dos pipelines. Indicadores das oportunidades que o chamador vê, de um pipeline (`pipelineId`) ou de todos: `kpis` (total, abertas e valor em aberto, ganhas e perdidas no período `from`..`to` com valor ganho, `conversionRate` = ganhas ÷ (ganhas + perdidas) em %, `avgCycleDays` da criação ao ganho), `ranking` por responsável (ordenado pelo valor ganho no período), `atRisk` (abertas sem movimento há `riskDays` dias, padrão 14, ou com `expectedCloseDate` vencida; até 50, mais paradas primeiro) e `lostReasons` (perdidas no período por `lost_reason`; `reason` null = sem motivo). Também devolve o que a Visão geral de oportunidades mostra: `pipelines` (contagens e valores por pipeline, para a lista lateral), `temperature` (abertas em quente, morno, frio e congelado: banda do contato; parada há 30 dias ou mais conta como congelada) e `activityMix` (tarefas criadas no período por tipo e as ligações concluídas). Em `atRisk`, `priority` é `high` (ação vencida ou parada há o dobro de `riskDays`) ou `attention`. Em `ranking`, `activities` são as tarefas do responsável criadas no período. Valores em centavos.

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

## Entrada

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

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "pipelineId": {
      "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|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "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|([+-](?:[01]\\d|2[0-3]):[0-5]\\d)))$"
    },
    "riskDays": {
      "type": "integer",
      "minimum": 1,
      "maximum": 365
    }
  },
  "required": [
    "from",
    "to"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/crm.pipelines_overview \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"from":"2026-10-01T00:00:00-03:00","to":"2026-10-31T23:59:59-03:00"}'
```

CLI:

```bash
node cli/atomiks.mjs crm.pipelines_overview --json '{"from":"2026-10-01T00:00:00-03:00","to":"2026-10-31T23:59:59-03:00"}'
```

MCP: ferramenta `crm_pipelines_overview` 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": {
    "kpis": {
      "type": "object",
      "properties": {
        "total": {
          "type": "number"
        },
        "open": {
          "type": "number"
        },
        "openValueCents": {
          "type": "number"
        },
        "won": {
          "type": "number"
        },
        "wonValueCents": {
          "type": "number"
        },
        "lost": {
          "type": "number"
        },
        "conversionRate": {
          "type": [
            "number",
            "null"
          ]
        },
        "avgCycleDays": {
          "type": [
            "number",
            "null"
          ]
        }
      },
      "required": [
        "total",
        "open",
        "openValueCents",
        "won",
        "wonValueCents",
        "lost",
        "conversionRate",
        "avgCycleDays"
      ],
      "additionalProperties": false
    },
    "ranking": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "userId": {
            "type": [
              "string",
              "null"
            ]
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "open": {
            "type": "number"
          },
          "won": {
            "type": "number"
          },
          "lost": {
            "type": "number"
          },
          "conversionRate": {
            "type": [
              "number",
              "null"
            ]
          },
          "wonValueCents": {
            "type": "number"
          },
          "avgCycleDays": {
            "type": [
              "number",
              "null"
            ]
          },
          "activities": {
            "type": "number"
          }
        },
        "required": [
          "userId",
          "name",
          "open",
          "won",
          "lost",
          "conversionRate",
          "wonValueCents",
          "avgCycleDays",
          "activities"
        ],
        "additionalProperties": false
      }
    },
    "atRisk": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "title": {
            "type": "string"
          },
          "pipelineId": {
            "type": "string"
          },
          "contactId": {
            "type": "string"
          },
          "contactName": {
            "type": [
              "string",
              "null"
            ]
          },
          "ownerId": {
            "type": [
              "string",
              "null"
            ]
          },
          "valueCents": {
            "type": "number"
          },
          "daysIdle": {
            "type": "number"
          },
          "expectedCloseDate": {
            "type": [
              "string",
              "null"
            ]
          },
          "reasons": {
            "type": "array",
            "items": {
              "type": "string",
              "enum": [
                "stalled",
                "overdue"
              ]
            }
          },
          "pipelineName": {
            "type": [
              "string",
              "null"
            ]
          },
          "ownerName": {
            "type": [
              "string",
              "null"
            ]
          },
          "noNextAction": {
            "type": "boolean"
          },
          "isFrozen": {
            "type": "boolean"
          },
          "priority": {
            "type": "string",
            "enum": [
              "high",
              "attention"
            ]
          }
        },
        "required": [
          "id",
          "title",
          "pipelineId",
          "contactId",
          "contactName",
          "ownerId",
          "valueCents",
          "daysIdle",
          "expectedCloseDate",
          "reasons",
          "pipelineName",
          "ownerName",
          "noNextAction",
          "isFrozen",
          "priority"
        ],
        "additionalProperties": false
      }
    },
    "atRiskTotal": {
      "type": "number"
    },
    "lostReasons": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "reason": {
            "type": [
              "string",
              "null"
            ]
          },
          "count": {
            "type": "number"
          },
          "valueCents": {
            "type": "number"
          }
        },
        "required": [
          "reason",
          "count",
          "valueCents"
        ],
        "additionalProperties": false
      }
    },
    "pipelines": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "total": {
            "type": "number"
          },
          "open": {
            "type": "number"
          },
          "openValueCents": {
            "type": "number"
          },
          "won": {
            "type": "number"
          },
          "wonValueCents": {
            "type": "number"
          },
          "lost": {
            "type": "number"
          },
          "lostValueCents": {
            "type": "number"
          }
        },
        "required": [
          "id",
          "name",
          "total",
          "open",
          "openValueCents",
          "won",
          "wonValueCents",
          "lost",
          "lostValueCents"
        ],
        "additionalProperties": false
      }
    },
    "temperature": {
      "type": "object",
      "properties": {
        "hot": {
          "type": "number"
        },
        "warm": {
          "type": "number"
        },
        "cold": {
          "type": "number"
        },
        "frozen": {
          "type": "number"
        }
      },
      "required": [
        "hot",
        "warm",
        "cold",
        "frozen"
      ],
      "additionalProperties": false
    },
    "activityMix": {
      "type": "object",
      "properties": {
        "calls": {
          "type": "number"
        },
        "whatsapp": {
          "type": "number"
        },
        "meetings": {
          "type": "number"
        },
        "notes": {
          "type": "number"
        },
        "callsAnswered": {
          "type": "number"
        },
        "callsTotal": {
          "type": "number"
        }
      },
      "required": [
        "calls",
        "whatsapp",
        "meetings",
        "notes",
        "callsAnswered",
        "callsTotal"
      ],
      "additionalProperties": false
    }
  },
  "required": [
    "kpis",
    "ranking",
    "atRisk",
    "atRiskTotal",
    "lostReasons",
    "pipelines",
    "temperature",
    "activityMix"
  ],
  "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).
