# Atendimentos

## Objetivo

A API de atendimentos (Contacts) tem por objetivo consultar os atendimentos de uma determinada instância do Zenvia NLU.

![](/files/DG1LoEnQOc3z8neJvE2f)

## Request

<mark style="color:green;">`POST`</mark> `https://api.altubots.com/contacts/<instancia>`

#### Headers

| Name      | Type     | Description |
| --------- | -------- | ----------- |
| x-api-key | \<token> |             |

{% tabs %}
{% tab title="200: OK OK - Contacts found" %}

```javascript
{
    "contacts": [
        ...
        {
            "id": 3213,
            "identifier": "52fe68c3-4501-cde1-e6fb-d3cb11d0ad9c",
            "assistantId": 1,
            "source": "widget",
            "externalId": null,
            "interactions": 30,
            "dateCreated": "2020-06-01"
            "finishedAt": "2020-06-03"
            "attributes": {
                "name": "...",
                "email": "...",
                ...
            },
            "history": [
                {
                    "time": "2020-06-01T12:45:59.158Z",
                    "sender": "bot",
                    "message": [
                        {
                            "text": "Olá! Eu sou o assistente virtual.",
                            "type": "text"
                        },
                        {
                            "text": "O que você deseja?",
                            "type": "text"
                        }
                    ]
                },
                ...
            ]
            "events": [
                ...
                {
                    "id": 13213,
                    "assistantId": 1,
                    "contactId": 16267,
                    "externalId": null,
                    "eventName": "transbordo",
                    "eventId": 12,
                    "extra1": null,
                    "extra2": null,
                    "details": {
                        "cpf": "12345678909",
                        "skill": "assistencia_tecnica"
                    },
                    "date": "2020-06-22 16:38:42"
                },
                ...
            ]
        },
        ...
    ]
    "resultCount": "150",
    "pagination": "Hash para consultar a próxima página"
}
```

{% endtab %}

{% tab title="400: Bad Request " %}

```javascript
{
    "message": "Bad request",
    "invalidParams": [
        ...
    ]
}
```

{% endtab %}

{% tab title="401: Unauthorized " %}

```javascript
{
    "message": "Unauthorized"
}
```

{% endtab %}

{% tab title="404: Not Found Contacts not found" %}

```javascript
{
    "contacts": [],
    "resultCount": 0
}
```

{% endtab %}

{% tab title="500: Internal Server Error " %}

```javascript
{
    "status": "error",
    "message": "Unexpected error"
}
```

{% endtab %}
{% endtabs %}

**Body template**

```javascript
{
    "filters": {
        "id": "ID do atendimento",
        "assistantId": "ID do assistente",
        "identifier": "Identifier do contato",
        "externalId": "External id do atendimento",
        "startDate": "Início do período da consulta (Y-m-d)",
        "endDate": "Fim do período da consulta (Y-m-d)",
        "source": "Canal de origem do atendimento",
        "limit": "Quantidade de resultados por página" //Default: 100 - max: 500
    }
    "attributes": {
        "cpf": "CPF do atendimento",
        "phone": "Telefone do atendimento",
        "email": "Email do atendimento",
        "identification_number": "Extra de identificação",
        "identification_number2": "Extra de identificação 2",
        "identification_number3": "Extra de identificação 3",
        "identification_number4": "Extra de identificação 4"        
    },
    "flags": {
        "history": "Boolean para trazer ou não o histórico de mensagens do atendimento",  //Default: false
        "events": "Boolean para trazer ou não o histórico de eventos do atendimento" //Default: false
    },
    "pagination": "Hash para consultar a próxima página"
}
```

## Limitações

* Máximo de resultados por consulta: 500
  * Utilizar paginação para buscar páginas seguintes
* Consultas que não tenham o filter `id`, `identifier` ou `phone` não retornarão histórico e eventos
* Um fluxo comum de requisições/consultas seria:
  1. Consultar pelo `assistantId`, `startDate` e `endDate`
  2. Em cada atendimento encontrado, usar o `id` ou `identifier` para fazer uma nova consulta com a flag `history: true` para buscar o histórico daquele atendimento
* Limite de 50000 consultas por dia e 10 por segundo

{% hint style="info" %}
O `pagination`é disponibilizado no **response da primeira consulta** para que você possa referenciá-lo no body da próxima consulta e assim sucessivamente.
{% endhint %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.altu.d1.cx/connect/apis/atendimentos.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
