# Contacts and consent

Numbers, countries, tags, import and opt-out.

Contacts are the people you write to. They are used to target your campaigns, fill a template's variables and respect opt-outs.

## Create or update a contact

`POST /contacts` creates a contact, or updates the one that already has this number. There are never two contacts for the same number.

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/contacts \
  -H "Authorization: Bearer pk_live_..." \
  -H "Content-Type: application/json" \
  -d '{"companyId":"cmp_...","phone":"+237 6 99 12 34 56","name":"Awa","tags":["VIP"],"consent":true}'
```

With a partner key, give `companyId`. A company key infers it.

## Numbers and countries

Numbers are normalised: `+237 6 99 12 34 56` and `237699123456` are the same contact. Several countries can live in one list.

A number written with `+` or `00` keeps its country. For a number written without a country code, the country is looked up in this order:

1. the row's `country` field (ISO code like `SN`, or dial code like `221`);
2. the request's `defaultCountryCode`;
3. the company's default country (`PATCH /companies/{id}` with `defaultCountry`);
4. Cameroon.

The local number length is checked for that country: a number that does not match is refused rather than guessed. `GET /countries` lists the recognised countries.

## Import a list

`POST /contacts/import` accepts JSON rows (`rows`) or a CSV file as text (`csv`), up to 50,000 rows.

```csv
phone,name,tags,consent,country,city
699123456,Awa,VIP,yes,CM,Douala
771234567,Moussa,"VIP;new",yes,SN,Dakar
```

The number, name, tags, consent and country columns are recognised. The others (here `city`) become fields you can use as template variables.

## Tags

Tags are for targeting: `GET /tags` gives each tag and its contact count. Change them with `PATCH /contacts/{id}` (`tags`, `addTags`, `removeTags`).

## Consent and opt-out

`consent: true` states that the person agreed to receive your messages. You are responsible for it: keep the proof (form, ticked box, conversation).

When a contact replies **STOP** (or `ARRET`, `UNSUBSCRIBE`, `DESINSCRIPTION` and a few variants), they are opted out automatically. `POST /contacts/{id}/opt-out` and `/opt-in` do the same from your system. An opted-out contact is set aside from every campaign, even while it is running, even for a utility template.

> **Good to know**

> A contact who wrote first can receive a service message for 24 hours with no other formality. For marketing, declared consent is still required.
