# ads_manager.tree

Árvore campanha, conjunto e anúncio com métricas da Meta e reais. Campanhas, conjuntos e anúncios da conta de anúncios conectada, com as métricas da Meta no período (gasto, impressões, cliques, CPM, CTR, CPC, `conversationsMeta` = conversas iniciadas segundo a Meta) ao lado das reais (`conversationsReal` = contatos cuja PRIMEIRA indicação é do anúncio, no dia do fuso da conta; `costPerConversationReal`) e as vendas: `sales` e `revenueCents` (vendas não canceladas do contato cuja PRIMEIRA indicação é do anúncio, com `sold_at` no dia do fuso da conta), `costPerSaleCents` (gasto ÷ vendas, em centavos) e `roas` (receita ÷ gasto). Somas sobem de anúncio para conjunto, campanha e `totals`; razões saem das somas e são `null` sem denominador. Item sem entrega no período aparece com zeros. `from` e `to` são datas `AAAA-MM-DD` (até 93 dias). Orçamentos em centavos. `adAccountId` (`act_...`) e `adAccountName` identificam a conta de anúncios conectada.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `from` | string | sim |  |
| `to` | string | sim |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "from": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    },
    "to": {
      "type": "string",
      "pattern": "^\\d{4}-\\d{2}-\\d{2}$"
    }
  },
  "required": [
    "from",
    "to"
  ]
}
```

</details>

## Exemplo

```bash
curl -X POST https://app.atomiks.com.br/api/v1/ads_manager.tree \
  -H "Authorization: Bearer $ATOMIKS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"from":"2026-10-01","to":"2026-10-07"}'
```

CLI:

```bash
node cli/atomiks.mjs ads_manager.tree --json '{"from":"2026-10-01","to":"2026-10-07"}'
```

MCP: ferramenta `ads_manager_tree` 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": {
    "currency": {
      "type": [
        "string",
        "null"
      ]
    },
    "timezone": {
      "type": [
        "string",
        "null"
      ]
    },
    "lastSyncedAt": {
      "type": [
        "string",
        "null"
      ]
    },
    "adAccountId": {
      "type": [
        "string",
        "null"
      ]
    },
    "adAccountName": {
      "type": [
        "string",
        "null"
      ]
    },
    "totals": {
      "type": "object",
      "properties": {
        "spend": {
          "type": "number"
        },
        "impressions": {
          "type": "number"
        },
        "clicks": {
          "type": "number"
        },
        "cpm": {
          "type": [
            "number",
            "null"
          ]
        },
        "ctr": {
          "type": [
            "number",
            "null"
          ]
        },
        "cpc": {
          "type": [
            "number",
            "null"
          ]
        },
        "conversationsMeta": {
          "type": "number"
        },
        "conversationsReal": {
          "type": "number"
        },
        "costPerConversationReal": {
          "type": [
            "number",
            "null"
          ]
        },
        "sales": {
          "type": "number"
        },
        "revenueCents": {
          "type": "number"
        },
        "costPerSaleCents": {
          "type": [
            "number",
            "null"
          ]
        },
        "roas": {
          "type": [
            "number",
            "null"
          ]
        }
      },
      "required": [
        "spend",
        "impressions",
        "clicks",
        "cpm",
        "ctr",
        "cpc",
        "conversationsMeta",
        "conversationsReal",
        "costPerConversationReal",
        "sales",
        "revenueCents",
        "costPerSaleCents",
        "roas"
      ],
      "additionalProperties": false
    },
    "campaigns": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/__schema0"
      }
    }
  },
  "required": [
    "currency",
    "timezone",
    "lastSyncedAt",
    "adAccountId",
    "adAccountName",
    "totals",
    "campaigns"
  ],
  "additionalProperties": false,
  "$defs": {
    "__schema0": {
      "type": "object",
      "properties": {
        "id": {
          "type": "string"
        },
        "level": {
          "type": "string",
          "enum": [
            "campaign",
            "adset",
            "ad"
          ]
        },
        "name": {
          "type": [
            "string",
            "null"
          ]
        },
        "configuredStatus": {
          "type": [
            "string",
            "null"
          ]
        },
        "effectiveStatus": {
          "type": [
            "string",
            "null"
          ]
        },
        "dailyBudget": {
          "type": [
            "number",
            "null"
          ]
        },
        "lifetimeBudget": {
          "type": [
            "number",
            "null"
          ]
        },
        "metrics": {
          "type": "object",
          "properties": {
            "spend": {
              "type": "number"
            },
            "impressions": {
              "type": "number"
            },
            "clicks": {
              "type": "number"
            },
            "cpm": {
              "type": [
                "number",
                "null"
              ]
            },
            "ctr": {
              "type": [
                "number",
                "null"
              ]
            },
            "cpc": {
              "type": [
                "number",
                "null"
              ]
            },
            "conversationsMeta": {
              "type": "number"
            },
            "conversationsReal": {
              "type": "number"
            },
            "costPerConversationReal": {
              "type": [
                "number",
                "null"
              ]
            },
            "sales": {
              "type": "number"
            },
            "revenueCents": {
              "type": "number"
            },
            "costPerSaleCents": {
              "type": [
                "number",
                "null"
              ]
            },
            "roas": {
              "type": [
                "number",
                "null"
              ]
            }
          },
          "required": [
            "spend",
            "impressions",
            "clicks",
            "cpm",
            "ctr",
            "cpc",
            "conversationsMeta",
            "conversationsReal",
            "costPerConversationReal",
            "sales",
            "revenueCents",
            "costPerSaleCents",
            "roas"
          ],
          "additionalProperties": false
        },
        "children": {
          "type": "array",
          "items": {
            "$ref": "#/$defs/__schema0"
          }
        }
      },
      "required": [
        "id",
        "level",
        "name",
        "configuredStatus",
        "effectiveStatus",
        "dailyBudget",
        "lifetimeBudget",
        "metrics",
        "children"
      ],
      "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).
