> For clean Markdown of any page, append .md to the page URL.
> For a complete documentation index, see https://docs.callix.dev.br/llms.txt.
> For AI client integration (Claude Code, Cursor, etc.), connect to the MCP server at https://docs.callix.dev.br/_mcp/server.

# Usando a API para iniciar atendimentos por WhatsApp

Para iniciar atendimentos por WhatsApp usando a API é preciso utilizar a interface do sistema para gerar um\
[token de acesso](/introducao/visao-geral#autenticação) da API.

## 1. Iniciar um atendimento por WhatsApp

Este endpoint permite iniciar um atendimento via WhatsApp enviando uma mensagem de template para um contato.

O atendimento pode ser encaminhado para:

* **Fila de WhatsApp**: O atendimento é encaminhado após o contato responder
* **Fluxo (Workflow)**: O atendimento é encaminhado após o contato responder
* **Agente**: O atendimento é encaminhado imediatamente ao agente
* **Agente na tela de atendimento**: Abre a tela de atendimento com o telefone pré-preenchido

> **Note**
>
> Os atendimentos iniciados serão listados no relatório em **Relatórios > WhatsApp > Ativo > Manual > Atendimentos**.

### Encaminhar para uma Fila

#### Exemplo de chamada:

```bash
curl -X POST "https://sua-conta.callix.com.br/api/v1/click_to_chat" \
  -H "Authorization: Bearer SEU_TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  -d '{
  "data": {
    "type": "click_to_chat",
    "attributes": {
      "phone": "11987654321",
      "inbound_number_id": 1,
      "template_id": 1,
      "target_type": 1,
      "queue_id": 1,
      "customer_id": 1,
      "terminate_ongoing_conversation": true,
      "template_variables": {
        "body": {
          "1": "12345",
          "2": "20/11/2024"
        }
      }
    }
  }
}'
```

### Encaminhar para um Fluxo

#### Exemplo de chamada:

```bash
curl -X POST "https://sua-conta.callix.com.br/api/v1/click_to_chat" \
  -H "Authorization: Bearer SEU_TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  -d '{
  "data": {
    "type": "click_to_chat",
    "attributes": {
      "phone": "11987654321",
      "inbound_number_id": 1,
      "template_id": 1,
      "target_type": 2,
      "workflow_id": 1,
      "customer_id": 1,
      "terminate_ongoing_conversation": true,
      "template_variables": {
        "body": {
          "1": "12345",
          "2": "20/11/2024"
        }
      }
    }
  }
}'
```

### Encaminhar para um Agente

#### Exemplo de chamada:

```bash
curl -X POST "https://sua-conta.callix.com.br/api/v1/click_to_chat" \
  -H "Authorization: Bearer SEU_TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  -d '{
  "data": {
    "type": "click_to_chat",
    "attributes": {
      "phone": "11987654321",
      "inbound_number_id": 1,
      "template_id": 1,
      "target_type": 3,
      "user_id": 1,
      "customer_id": 1,
      "template_variables": {
        "body": {
          "1": "12345",
          "2": "20/11/2024"
        }
      }
    }
  }
}'
```

### Encaminhar para Agente na Tela de Atendimento

#### Exemplo de chamada:

```bash
curl -X POST "https://sua-conta.callix.com.br/api/v1/click_to_chat" \
  -H "Authorization: Bearer SEU_TOKEN" \
  -H "Content-Type: application/vnd.api+json" \
  -d '{
  "data": {
    "type": "click_to_chat",
    "attributes": {
      "phone": "11987654321",
      "target_type": 4,
      "user_id": 1
    }
  }
}'
```

## Exemplos de Resposta

#### Resposta padrão:

```json
{
  "message": "Request processed successfully"
}
```

#### Resposta quando o dígito 9 é adicionado automaticamente:

```json
{
  "message": "The digit 9 was automatically added to the phone number as it is a brazilian mobile number",
  "phone": "11987654321"
}
```

> **Note**
>
> Para números brasileiros de celular, o dígito 9 pode ser adicionado automaticamente se não estiver presente. Neste caso, os campos `message` e `phone` serão incluídos na resposta com informações sobre a correção aplicada.

## Atributos

### Atributos da Requisição

| Atributo                         | Tipo    | Obrigatório     | Descrição                                                                    |
| -------------------------------- | ------- | --------------- | ---------------------------------------------------------------------------- |
| `phone`                          | string  | Sim             | Telefone que irá receber a mensagem                                          |
| `inbound_number_id`              | number  | Condicional\*   | ID do número WhatsApp a ser usado para enviar a mensagem                     |
| `inbound_number_phone`           | string  | Condicional\*   | Telefone do número WhatsApp a ser usado                                      |
| `template_id`                    | number  | Não             | ID do template WhatsApp a ser usado na mensagem                              |
| `target_type`                    | number  | Sim             | Tipo de destino: `1` = Fila, `2` = Fluxo, `3` = Agente, `4` = Agente na tela |
| `queue_id`                       | number  | Condicional\*\* | ID da Fila de WhatsApp (obrigatório se `target_type = 1`)                    |
| `workflow_id`                    | number  | Condicional\*\* | ID do Fluxo (obrigatório se `target_type = 2`)                               |
| `user_id`                        | number  | Condicional\*\* | ID do agente (obrigatório se `target_type = 3` ou `4`)                       |
| `customer_id`                    | number  | Não             | ID do cliente para associar ao atendimento                                   |
| `terminate_ongoing_conversation` | boolean | Não             | Se deve encerrar conversa em andamento                                       |
| `template_variables`             | object  | Não             | Variáveis do template (ver estrutura abaixo)                                 |

\* Um dos dois (`inbound_number_id` ou `inbound_number_phone`) é obrigatório\
\*\* Obrigatório dependendo do `target_type`

### Estrutura de template_variables

```json
{
  "body": {
    "1": "Valor para variável 1",
    "2": "Valor para variável 2"
  },
  "header": {
    "format": "TEXT",
    "text": "Texto do cabeçalho"
  }
}
```

### Tipos de Target

| Valor | Descrição                     | Campo Obrigatório |
| ----- | ----------------------------- | ----------------- |
| `1`   | Fila                          | `queue_id`        |
| `2`   | Fluxo                         | `workflow_id`     |
| `3`   | Agente                        | `user_id`         |
| `4`   | Agente na tela de atendimento | `user_id`         |

## Códigos de Resposta

| Código HTTP | Descrição                                                               |
| ----------- | ----------------------------------------------------------------------- |
| `200`       | Requisição processada com sucesso                                       |
| `400`       | Requisição inválida (campos obrigatórios ausentes ou formato incorreto) |
| `401`       | Token de autenticação inválido ou ausente                               |
| `404`       | Recurso não encontrado (número, fila, fluxo, agente ou cliente)         |