# subscriptions.cohort

Coortes de assinaturas. Quanto de cada safra (semana ou mês de ativação) segue assinando ao longo do tempo: `retentionPercentage` de 0 a 1 por coluna (a coluna 0 é a safra; vem `null` onde a safra ainda não chegou). Filtra por entrada na base, UTMs, produto, oferta e método de pagamento; `funnelIds` com valor deixa a matriz vazia (sem fonte).

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `bucket` | "week" \| "month" | não |  |
| `enteredFrom` | string | não |  |
| `enteredTo` | string | não |  |
| `utmSources` | string[] | não |  |
| `utmMediums` | string[] | não |  |
| `utmCampaigns` | string[] | não |  |
| `utmTerms` | string[] | não |  |
| `productIds` | string[] | não |  |
| `offerIds` | string[] | não |  |
| `funnelIds` | string[] | não |  |
| `paymentMethods` | "credit" \| "pix" \| "boleto"[] | não |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "bucket": {
      "type": "string",
      "enum": [
        "week",
        "month"
      ]
    },
    "enteredFrom": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "enteredTo": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "utmSources": {
      "maxItems": 200,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 120
      }
    },
    "utmMediums": {
      "maxItems": 200,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 120
      }
    },
    "utmCampaigns": {
      "maxItems": 200,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 120
      }
    },
    "utmTerms": {
      "maxItems": 200,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 120
      }
    },
    "productIds": {
      "maxItems": 200,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 120
      }
    },
    "offerIds": {
      "maxItems": 200,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 120
      }
    },
    "funnelIds": {
      "maxItems": 200,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 120
      }
    },
    "paymentMethods": {
      "maxItems": 3,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "credit",
          "pix",
          "boleto"
        ]
      }
    }
  }
}
```

</details>

## Exemplo

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

CLI:

```bash
node cli/atomiks.mjs subscriptions.cohort --json '{"bucket":"week"}'
```

MCP: ferramenta `subscriptions_cohort` 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": {
    "columns": {
      "type": "number"
    },
    "rows": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "period": {
            "type": "string"
          },
          "size": {
            "type": "number"
          },
          "retentionPercentage": {
            "type": "array",
            "items": {
              "type": [
                "number",
                "null"
              ]
            }
          }
        },
        "required": [
          "period",
          "size",
          "retentionPercentage"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "columns",
    "rows"
  ],
  "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).
