# segmentation.tag_usage

Uso e insights de uma tag. Painel da tag e confirmação de exclusão: contatos, oportunidades, automações e segmentos que a usam (`references`, com `kind` flow ou segment e o nome), `coverage` (contatos com a tag / contatos da conta), aplicações nos últimos 30 dias, `trend` (acumulado de 6 meses), `dailyApplied` (14 dias), `lastAppliedAt` e uma prévia de até 5 contatos (`leadsPreview`) que perdem a tag se ela for apagada.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `id` | string (uuid) | sim |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "id": {
      "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": [
    "id"
  ]
}
```

</details>

## Exemplo

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

CLI:

```bash
node cli/atomiks.mjs segmentation.tag_usage --json '{"id":"00000000-0000-0000-0000-000000000000"}'
```

MCP: ferramenta `segmentation_tag_usage` 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": {
    "id": {
      "type": "string"
    },
    "name": {
      "type": "string"
    },
    "color": {
      "type": "string"
    },
    "tagId": {
      "type": "string"
    },
    "leadsCount": {
      "type": "number"
    },
    "opportunitiesCount": {
      "type": "number"
    },
    "flowsCount": {
      "type": "number"
    },
    "segmentsCount": {
      "type": "number"
    },
    "totalLeads": {
      "type": "number"
    },
    "coverage": {
      "type": "number"
    },
    "appliedLast30Days": {
      "type": "number"
    },
    "usageCount": {
      "type": "number"
    },
    "lastAppliedAt": {
      "type": [
        "string",
        "null"
      ]
    },
    "createdAt": {
      "type": "string"
    },
    "updatedAt": {
      "type": "string"
    },
    "trend": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "month": {
            "type": "string"
          },
          "leads": {
            "type": "number"
          }
        },
        "required": [
          "month",
          "leads"
        ],
        "additionalProperties": false
      }
    },
    "dailyApplied": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "date": {
            "type": "string"
          },
          "count": {
            "type": "number"
          }
        },
        "required": [
          "date",
          "count"
        ],
        "additionalProperties": false
      }
    },
    "flows": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name"
        ],
        "additionalProperties": false
      }
    },
    "segments": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          }
        },
        "required": [
          "id",
          "name"
        ],
        "additionalProperties": false
      }
    },
    "references": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "kind": {
            "type": "string",
            "enum": [
              "flow",
              "segment"
            ]
          },
          "id": {
            "type": "string"
          },
          "name": {
            "type": "string"
          },
          "meta": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "kind",
          "id",
          "name",
          "meta"
        ],
        "additionalProperties": false
      }
    },
    "referencesTotal": {
      "type": "number"
    },
    "health": {
      "type": "string",
      "enum": [
        "healthy",
        "attention",
        "critical",
        "unused"
      ]
    },
    "leadsPreview": {
      "type": "array",
      "items": {
        "type": "object",
        "properties": {
          "leadId": {
            "type": "string"
          },
          "name": {
            "type": [
              "string",
              "null"
            ]
          },
          "email": {
            "type": [
              "string",
              "null"
            ]
          },
          "telephone": {
            "type": [
              "string",
              "null"
            ]
          }
        },
        "required": [
          "leadId",
          "name",
          "email",
          "telephone"
        ],
        "additionalProperties": false
      }
    }
  },
  "required": [
    "id",
    "name",
    "color",
    "tagId",
    "leadsCount",
    "opportunitiesCount",
    "flowsCount",
    "segmentsCount",
    "totalLeads",
    "coverage",
    "appliedLast30Days",
    "usageCount",
    "lastAppliedAt",
    "createdAt",
    "updatedAt",
    "trend",
    "dailyApplied",
    "flows",
    "segments",
    "references",
    "referencesTotal",
    "health",
    "leadsPreview"
  ],
  "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).
