# Contatti

> Consulta e aggiorna le informazioni dei contatti

- Pagina: https://tbit.app/it/docs/api/contacts
- URL base: `https://rest-api.tbit.app/v1`
- Autenticazione: header `X-API-Key` con la tua chiave in ogni richiesta (gli esempi la leggono dalla variabile d'ambiente `TBIT_API_KEY`)

## Panoramica

I contatti sono le persone che interagiscono con il tuo agente attraverso canali come WhatsApp, Instagram ed email. Ogni contatto ha un profilo con nome, identificativi di canale e metadati facoltativi.

## Endpoint

| Metodo | Percorso | Descrizione |
| --- | --- | --- |
| `GET` | `/v1/contacts` | Elenca i contatti |
| `GET` | `/v1/contacts/:id` | Dettaglio di un contatto |
| `POST` | `/v1/contacts` | Crea un nuovo contatto |
| `PATCH` | `/v1/contacts/:id` | Aggiorna un contatto |

## Parametri di query

L'endpoint di elenco supporta i seguenti parametri di query:

| Parametro | Tipo | Descrizione |
| --- | --- | --- |
| `limit` | `number` | Risultati per pagina (predefinito: 20, max: 100) |
| `offset` | `number` | Numero di risultati da saltare (predefinito: 0) |

## Elencare i contatti

`GET /v1/contacts`

```bash
curl "https://rest-api.tbit.app/v1/contacts?limit=20&offset=0" \
  -H "X-API-Key: $TBIT_API_KEY"
```

## Ottenere il dettaglio di un contatto

`GET /v1/contacts/64f1a2b3c4d5e6f7a8b9c0d1`

```bash
curl "https://rest-api.tbit.app/v1/contacts/64f1a2b3c4d5e6f7a8b9c0d1" \
  -H "X-API-Key: $TBIT_API_KEY"
```

## Aggiornare un contatto

`PATCH /v1/contacts/64f1a2b3c4d5e6f7a8b9c0d1`

```bash
curl -X PATCH "https://rest-api.tbit.app/v1/contacts/64f1a2b3c4d5e6f7a8b9c0d1" \
  -H "X-API-Key: $TBIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "profile_name": "Jane Doe",
    "email": "jane@example.com",
    "notes": "Preferred language: English"
  }'
```

## Creare un contatto

`POST /v1/contacts`

```bash
curl -X POST "https://rest-api.tbit.app/v1/contacts" \
  -H "X-API-Key: $TBIT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "channel_id": "573009876543",
    "channel_type": "whatsapp",
    "profile_name": "Jane Doe",
    "custom_attributes": {
      "city": "Bogota",
      "plan": "premium"
    }
  }'
```

## Formato della risposta

Gli endpoint di elenco restituiscono risultati paginati:

```json
{
  "data": [
    {
      "id": "64f1a2b3c4d5e6f7a8b9c0d1",
      "profile_name": "Jane Doe",
      "email": "jane@example.com",
      "notes": "Preferred language: English",
      "channels": [
        {
          "channel_id": "573001234567",
          "channel_type": "whatsapp"
        }
      ],
      "custom_attributes": {
        "city": "Bogota",
        "plan": "premium"
      },
      "created_at": "2024-09-01T12:00:00Z",
      "updated_at": "2024-09-01T14:30:00Z"
    }
  ],
  "pagination": {
    "total": 50,
    "limit": 20,
    "offset": 0,
    "has_more": true
  }
}
```
