# visitors.export

Exportar visitantes em CSV. CSV com um visitante por linha dos que batem com a busca e os filtros (mesmos de `visitors.list`): ID, acessos, sessões, canal, dispositivo, última página e funil, e o contato vinculado. Devolve `filename`, `csv` (texto) e `count`. Sem rastreio no Atomiks, só o cabeçalho.

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

## Entrada

| Campo | Tipo | Obrigatório | Nota |
|---|---|---|---|
| `search` | string | não |  |
| `projectIds` | string[] | não |  |
| `excludeProjectIds` | string[] | não |  |
| `pageIds` | string[] | não |  |
| `excludePageIds` | string[] | não |  |
| `funnelIds` | string[] | não |  |
| `excludeFunnelIds` | string[] | não |  |
| `channels` | "google" \| "facebook" \| "instagram" \| "tiktok" \| "youtube" \| "linkedin" \| "whatsapp" \| "email" \| "referral" \| "direct" \| "other"[] | não |  |
| `excludeChannels` | "google" \| "facebook" \| "instagram" \| "tiktok" \| "youtube" \| "linkedin" \| "whatsapp" \| "email" \| "referral" \| "direct" \| "other"[] | não |  |
| `hasLead` | boolean | não |  |

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

```json
{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "type": "object",
  "properties": {
    "search": {
      "type": "string",
      "maxLength": 120
    },
    "projectIds": {
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 80
      }
    },
    "excludeProjectIds": {
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 80
      }
    },
    "pageIds": {
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 80
      }
    },
    "excludePageIds": {
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 80
      }
    },
    "funnelIds": {
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 80
      }
    },
    "excludeFunnelIds": {
      "maxItems": 100,
      "type": "array",
      "items": {
        "type": "string",
        "maxLength": 80
      }
    },
    "channels": {
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "google",
          "facebook",
          "instagram",
          "tiktok",
          "youtube",
          "linkedin",
          "whatsapp",
          "email",
          "referral",
          "direct",
          "other"
        ]
      }
    },
    "excludeChannels": {
      "maxItems": 20,
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "google",
          "facebook",
          "instagram",
          "tiktok",
          "youtube",
          "linkedin",
          "whatsapp",
          "email",
          "referral",
          "direct",
          "other"
        ]
      }
    },
    "hasLead": {
      "type": "boolean"
    }
  }
}
```

</details>

## Exemplo

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

CLI:

```bash
node cli/atomiks.mjs visitors.export --json '{}'
```

MCP: ferramenta `visitors_export` 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": {
    "filename": {
      "type": "string"
    },
    "csv": {
      "type": "string"
    },
    "count": {
      "type": "number"
    }
  },
  "required": [
    "filename",
    "csv",
    "count"
  ],
  "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).
