# Référence de l'API

Chaque route, ses champs et un exemple.

# Référence API

Base URL: https://hira.localtechstudio.com/api/v1

## Messages

### GET /messages

Historique d'une conversation (`connectionId` + `to` E.164, curseur `after`)

```bash
curl https://hira.localtechstudio.com/api/v1/messages \
  -H "Authorization: Bearer pk_live_…"
```

### POST /messages

Envoyer un message (un seul champ de contenu ; types : text, image, video, document, audio, template, product, productList, …)

- `connectionId`: string
- `to`: string
- `text`: string
- `image`: object
- `document`: object
- `audio`: object
- `template`: object
- `buttons`: object
- `list`: object
- `cta`: object
- `smart`: object
- `otp`: object
- `flow`: object
- `callPermissionRequest`: object
- `reaction`: object
- `raw`: object

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/messages \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"connectionId":"con_01H…","to":"+237600000000","text":"Bonjour"}'
```

### GET /messages/{id}

Statut d'un message

```bash
curl https://hira.localtechstudio.com/api/v1/messages/… \
  -H "Authorization: Bearer pk_live_…"
```

## Numéros connectés

### POST /connect-links

Créer un lien de connexion à usage unique (clé partenaire requise). `externalRef` et `expiresInMinutes` sont optionnels (60 par défaut, 10 080 au maximum) ; l'`url` n'est renvoyée qu'une fois

- `externalRef`: string
- `expiresInMinutes`: integer

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/connect-links \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"externalRef":"client-4821","expiresInMinutes":60}'
```

### GET /connections

Lister les numéros connectés

```bash
curl https://hira.localtechstudio.com/api/v1/connections \
  -H "Authorization: Bearer pk_live_…"
```

### GET /connections/{id}

Détail d'une connexion (sans token)

```bash
curl https://hira.localtechstudio.com/api/v1/connections/… \
  -H "Authorization: Bearer pk_live_…"
```

### DELETE /connections/{id}

Déconnecter un numéro de la plateforme (jeton vidé, statut disconnected). La reconnexion via Embedded Signup réutilise le même enregistrement et ne consomme pas de slot supplémentaire

```bash
curl -X DELETE https://hira.localtechstudio.com/api/v1/connections/… \
  -H "Authorization: Bearer pk_live_…"
```

### GET /connections/{id}/catalogs

Catalogues produits Meta liés à la WABA

```bash
curl https://hira.localtechstudio.com/api/v1/connections/…/catalogs \
  -H "Authorization: Bearer pk_live_…"
```

### GET /connections/{id}/catalogs/{catalogId}/products

Produits d'un catalogue Meta

```bash
curl https://hira.localtechstudio.com/api/v1/connections/…/catalogs/…/products \
  -H "Authorization: Bearer pk_live_…"
```

### GET /connections/{id}/calling

Réglages d'appel du numéro

```bash
curl https://hira.localtechstudio.com/api/v1/connections/…/calling \
  -H "Authorization: Bearer pk_live_…"
```

### PATCH /connections/{id}/calling

Modifier les réglages d'appel : activation, icône d'appel, heures d'ouverture, permission de rappel

- `status`: ENABLED | DISABLED
- `callIconVisibility`: DEFAULT | DISABLE_ALL
- `callbackPermissionStatus`: ENABLED | DISABLED
- `callHours`: object

```bash
curl -X PATCH https://hira.localtechstudio.com/api/v1/connections/…/calling \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"status":"ENABLED","callIconVisibility":"DEFAULT","callbackPermissionStatus":"ENABLED","callHours":{"status":"ENABLED","timezoneId":"string","weeklyOperatingHours":["string"],"holidaySchedule":["string"]}}'
```

### GET /connections/{id}/call-permissions

Permission d'appel d'un client (paramètre `to`) et limites restantes

```bash
curl https://hira.localtechstudio.com/api/v1/connections/…/call-permissions \
  -H "Authorization: Bearer pk_live_…"
```

## Contacts et tags

### GET /contacts

Lister les contacts (filtres companyId, tag, q, optedOut)

```bash
curl https://hira.localtechstudio.com/api/v1/contacts \
  -H "Authorization: Bearer pk_live_…"
```

### POST /contacts

Créer ou mettre à jour un contact par numéro (normalisé, un seul contact par numéro)

- `companyId`: string
- `phone`: string
- `country`: string
- `name`: string
- `fields`: object
- `tags`: array
- `consent`: boolean

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

### POST /contacts/import

Importer des contacts (rows JSON ou csv texte, 50 000 lignes max). Colonnes reconnues : numéro, nom, tags, consentement, pays (CM, SN, FR ou 237, ligne par ligne) ; les autres colonnes deviennent des champs utilisables dans les variables

- `companyId`: string
- `rows`: array
- `csv`: string
- `tags`: array
- `consent`: boolean
- `defaultCountryCode`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/contacts/import \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"companyId":"string","rows":[{}],"csv":"string","tags":["string"],"consent":true,"defaultCountryCode":"string"}'
```

### GET /contacts/{id}

Détail d'un contact

```bash
curl https://hira.localtechstudio.com/api/v1/contacts/… \
  -H "Authorization: Bearer pk_live_…"
```

### PATCH /contacts/{id}

Modifier un contact (name, fields, tags, addTags, removeTags, consent)

```bash
curl -X PATCH https://hira.localtechstudio.com/api/v1/contacts/… \
  -H "Authorization: Bearer pk_live_…"
```

### DELETE /contacts/{id}

Supprimer un contact

```bash
curl -X DELETE https://hira.localtechstudio.com/api/v1/contacts/… \
  -H "Authorization: Bearer pk_live_…"
```

### POST /contacts/{id}/opt-out

Désinscrire un contact : écarté de toute campagne, y compris en cours

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/contacts/…/opt-out \
  -H "Authorization: Bearer pk_live_…"
```

### POST /contacts/{id}/opt-in

Réinscrire un contact qui a redonné son consentement

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/contacts/…/opt-in \
  -H "Authorization: Bearer pk_live_…"
```

### GET /tags

Lister les tags et le nombre de contacts

```bash
curl https://hira.localtechstudio.com/api/v1/tags \
  -H "Authorization: Bearer pk_live_…"
```

## Campagnes

### GET /campaigns

Lister les campagnes (filtres status, connectionId)

```bash
curl https://hira.localtechstudio.com/api/v1/campaigns \
  -H "Authorization: Bearer pk_live_…"
```

### POST /campaigns

Préparer une campagne (brouillon). Contenu : `template` (Meta) ou `text` (message libre 24 h : {{name}}, {{phone}}, {{ville}} ou {{field:ville}}, {{date}}, {{entreprise}}, {{numero}}…). Destinataires : `recipients` et/ou `audience`. STOP écarté ; MARKETING : consentement. Hors fenêtre → `window_closed`.

- `connectionId`: string
- `template`: object
- `text`: string
- `name`: string
- `recipients`: array
- `audience`: object
- `variableMap`: array
- `requireConsent`: boolean
- `defaultCountryCode`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/campaigns \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"connectionId":"con_01H…","template":{"name":"promo","language":"fr"},"audience":{"tags":["VIP"]},"variableMap":[{"source":"name","default":"cliente"}]}'
```

### GET /campaigns/{id}

Détail de la campagne et de ses destinataires

```bash
curl https://hira.localtechstudio.com/api/v1/campaigns/… \
  -H "Authorization: Bearer pk_live_…"
```

### GET /campaigns/{id}/preview

Vérifier avant envoi : destinataires retenus, écartés par raison, durée estimée, palier et qualité du numéro, quota

```bash
curl https://hira.localtechstudio.com/api/v1/campaigns/…/preview \
  -H "Authorization: Bearer pk_live_…"
```

### POST /campaigns/{id}/launch

Lancer une campagne, ou la programmer avec `scheduledAt` (jusqu'à 60 jours). La liste est vérifiée contre le quota et le palier d'envoi du numéro avant le premier envoi

- `scheduledAt`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/campaigns/…/launch \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"scheduledAt":"2026-12-01T08:00:00Z"}'
```

### POST /campaigns/{id}/pause

Mettre en pause une campagne en cours (effet immédiat)

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/campaigns/…/pause \
  -H "Authorization: Bearer pk_live_…"
```

### POST /campaigns/{id}/resume

Reprendre une campagne en pause

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/campaigns/…/resume \
  -H "Authorization: Bearer pk_live_…"
```

### POST /campaigns/{id}/cancel

Annuler une campagne : les envois restants sont écartés

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/campaigns/…/cancel \
  -H "Authorization: Bearer pk_live_…"
```

### POST /campaigns/{id}/test

Envoyer un test à un numéro (compte dans le quota)

- `to`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/campaigns/…/test \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"to":"string"}'
```

### GET /campaigns/{id}/report

Rapport : taux de livraison, lecture, réponse, clic, STOP, courbe heure par heure, causes d'échec

```bash
curl https://hira.localtechstudio.com/api/v1/campaigns/…/report \
  -H "Authorization: Bearer pk_live_…"
```

### GET /campaigns/{id}/export

Export CSV de chaque destinataire et de son statut

```bash
curl https://hira.localtechstudio.com/api/v1/campaigns/…/export \
  -H "Authorization: Bearer pk_live_…"
```

### POST /campaigns/{id}/retarget

Relancer : crée un brouillon avec ceux qui n'ont pas lu (not_read), pas répondu (not_replied) ou en échec (failed)

- `mode`: not_read | not_replied | failed
- `name`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/campaigns/…/retarget \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"mode":"not_read"}'
```

## Automations

### GET /automations

Lister les automations (filtre connectionId)

```bash
curl https://hira.localtechstudio.com/api/v1/automations \
  -H "Authorization: Bearer pk_live_…"
```

### POST /automations

Créer une automation. Déclencheurs : message_received, contact_created, campaign_completed, conversation_unanswered. Actions (max 5) : send_smart, send_template, add_tag, notify_team, webhook, send_flow, assign_conversation. Conditions optionnelles : text_contains, has_tag, not_has_tag, unanswered_minutes.

- `connectionId`: string
- `name`: string
- `enabled`: boolean
- `trigger`: message_received | contact_created | campaign_completed | conversation_unanswered
- `conditions`: array
- `actions`: array

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/automations \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"connectionId":"con_01H…","name":"Accueil","trigger":"message_received","actions":[{"type":"add_tag","tag":"a_ecrit"}]}'
```

### GET /automations/{id}

Détail d'une automation

```bash
curl https://hira.localtechstudio.com/api/v1/automations/… \
  -H "Authorization: Bearer pk_live_…"
```

### PATCH /automations/{id}

Modifier une automation

```bash
curl -X PATCH https://hira.localtechstudio.com/api/v1/automations/… \
  -H "Authorization: Bearer pk_live_…"
```

### DELETE /automations/{id}

Supprimer une automation

```bash
curl -X DELETE https://hira.localtechstudio.com/api/v1/automations/… \
  -H "Authorization: Bearer pk_live_…"
```

### GET /automations/{id}/runs

Historique des exécutions

```bash
curl https://hira.localtechstudio.com/api/v1/automations/…/runs \
  -H "Authorization: Bearer pk_live_…"
```

## Templates et médias

### POST /templates/sync

Synchroniser les templates depuis Meta

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/templates/sync \
  -H "Authorization: Bearer pk_live_…"
```

### GET /templates

Lister les templates

```bash
curl https://hira.localtechstudio.com/api/v1/templates \
  -H "Authorization: Bearer pk_live_…"
```

### POST /templates

Créer un template

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/templates \
  -H "Authorization: Bearer pk_live_…"
```

### GET /templates/{id}

Détail d'un template

```bash
curl https://hira.localtechstudio.com/api/v1/templates/… \
  -H "Authorization: Bearer pk_live_…"
```

### DELETE /templates/{id}

Supprimer un template

```bash
curl -X DELETE https://hira.localtechstudio.com/api/v1/templates/… \
  -H "Authorization: Bearer pk_live_…"
```

### POST /media

Téléverser un média (multipart, champ file) ; dédupliqué, quota en octets neufs

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/media \
  -H "Authorization: Bearer pk_live_…"
```

### POST /media/header-handle

Obtenir un header_handle pour un template

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/media/header-handle \
  -H "Authorization: Bearer pk_live_…"
```

## Webhooks

### GET /webhook-endpoints

Lister les webhooks sortants

```bash
curl https://hira.localtechstudio.com/api/v1/webhook-endpoints \
  -H "Authorization: Bearer pk_live_…"
```

### POST /webhook-endpoints

Créer un webhook (secret whsec_… affiché une fois ; livraisons signées X-Wa-Signature)

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/webhook-endpoints \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://example.com/webhooks/whatsapp","scope":"account"}'
```

### PATCH /webhook-endpoints/{id}

Modifier l'URL ou le filtre `events` d'un webhook

```bash
curl -X PATCH https://hira.localtechstudio.com/api/v1/webhook-endpoints/… \
  -H "Authorization: Bearer pk_live_…"
```

### DELETE /webhook-endpoints/{id}

Supprimer un webhook

```bash
curl -X DELETE https://hira.localtechstudio.com/api/v1/webhook-endpoints/… \
  -H "Authorization: Bearer pk_live_…"
```

### GET /flow-endpoints

Lister les callbacks Flows

```bash
curl https://hira.localtechstudio.com/api/v1/flow-endpoints \
  -H "Authorization: Bearer pk_live_…"
```

### POST /flow-endpoints

Créer un callback Flows

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/flow-endpoints \
  -H "Authorization: Bearer pk_live_…"
```

### PATCH /flow-endpoints/{id}

Modifier l'URL d'un callback Flows

```bash
curl -X PATCH https://hira.localtechstudio.com/api/v1/flow-endpoints/… \
  -H "Authorization: Bearer pk_live_…"
```

### DELETE /flow-endpoints/{id}

Supprimer un callback Flows

```bash
curl -X DELETE https://hira.localtechstudio.com/api/v1/flow-endpoints/… \
  -H "Authorization: Bearer pk_live_…"
```

## Appels

### GET /calls

Lister les appels (filtres connectionId, direction, status)

```bash
curl https://hira.localtechstudio.com/api/v1/calls \
  -H "Authorization: Bearer pk_live_…"
```

### POST /calls

Lancer un appel sortant avec une offre SDP (permission du client requise)

- `connectionId`: string
- `to`: string
- `sdpOffer`: string
- `bizOpaqueCallbackData`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/calls \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"connectionId":"con_01H…","to":"+237600000000","sdpOffer":"v=0…"}'
```

### GET /calls/{id}

Détail d'un appel (identifiant cal_… ou identifiant Meta wacid…)

```bash
curl https://hira.localtechstudio.com/api/v1/calls/… \
  -H "Authorization: Bearer pk_live_…"
```

### POST /calls/{id}/pre-accept

Pré-accepter un appel entrant avec la réponse SDP

- `sdpAnswer`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/calls/…/pre-accept \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"sdpAnswer":"string"}'
```

### POST /calls/{id}/accept

Accepter un appel entrant avec la réponse SDP

- `sdpAnswer`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/calls/…/accept \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"sdpAnswer":"v=0…"}'
```

### POST /calls/{id}/reject

Refuser un appel entrant

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/calls/…/reject \
  -H "Authorization: Bearer pk_live_…"
```

### POST /calls/{id}/terminate

Raccrocher un appel

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/calls/…/terminate \
  -H "Authorization: Bearer pk_live_…"
```

## WhatsApp Flows

### GET /flows

Lister les Flows

```bash
curl https://hira.localtechstudio.com/api/v1/flows \
  -H "Authorization: Bearer pk_live_…"
```

### POST /flows

Créer un Flow

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/flows \
  -H "Authorization: Bearer pk_live_…"
```

### GET /flows/{id}

Détail d'un Flow

```bash
curl https://hira.localtechstudio.com/api/v1/flows/… \
  -H "Authorization: Bearer pk_live_…"
```

### PATCH /flows/{id}

Modifier un Flow

```bash
curl -X PATCH https://hira.localtechstudio.com/api/v1/flows/… \
  -H "Authorization: Bearer pk_live_…"
```

### DELETE /flows/{id}

Supprimer un Flow

```bash
curl -X DELETE https://hira.localtechstudio.com/api/v1/flows/… \
  -H "Authorization: Bearer pk_live_…"
```

### POST /flows/{id}/publish

Publier un Flow

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/flows/…/publish \
  -H "Authorization: Bearer pk_live_…"
```

## Entreprises et pays

### GET /companies

Lister les entreprises

```bash
curl https://hira.localtechstudio.com/api/v1/companies \
  -H "Authorization: Bearer pk_live_…"
```

### POST /companies

Créer une entreprise (clé partenaire). À partir de la 2ᵉ, exige la feature `multi_company` (plan Business)

- `name`: string
- `externalRef`: string
- `defaultCountry`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/companies \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"name":"string","externalRef":"string","defaultCountry":"string"}'
```

### PATCH /companies/{id}

Définir le pays par défaut de l'entreprise (`defaultCountry`, code ISO ou indicatif, null pour revenir au défaut du service) : il sert aux numéros écrits sans indicatif

- `defaultCountry`: string | null

```bash
curl -X PATCH https://hira.localtechstudio.com/api/v1/companies/… \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"defaultCountry":"string"}'
```

### GET /countries

Pays reconnus pour la normalisation des numéros (code, nom, indicatif)

```bash
curl https://hira.localtechstudio.com/api/v1/countries \
  -H "Authorization: Bearer pk_live_…"
```

## Clés d'accès

### GET /api-keys

Lister les clés API

```bash
curl https://hira.localtechstudio.com/api/v1/api-keys \
  -H "Authorization: Bearer pk_live_…"
```

### POST /api-keys

Créer une clé (secret en clair une seule fois, clé partenaire requise)

- `scope`: partner | company
- `companyId`: string
- `name`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/api-keys \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"scope":"partner","companyId":"string","name":"string"}'
```

### DELETE /api-keys/{id}

Révoquer une clé

```bash
curl -X DELETE https://hira.localtechstudio.com/api/v1/api-keys/… \
  -H "Authorization: Bearer pk_live_…"
```

### POST /api-keys/{id}/rotate

Renouveler une clé : une nouvelle clé est créée (secret en clair une seule fois) et l'ancienne reste valable 24 heures (clé partenaire requise)

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/api-keys/…/rotate \
  -H "Authorization: Bearer pk_live_…"
```

## Abonnement et facturation

### GET /plans

Plans et prix par devise (PROVISOIRES)

```bash
curl https://hira.localtechstudio.com/api/v1/plans \
  -H "Authorization: Bearer pk_live_…"
```

### GET /subscription

Abonnement, limites et consommation du compte (clé partenaire)

```bash
curl https://hira.localtechstudio.com/api/v1/subscription \
  -H "Authorization: Bearer pk_live_…"
```

### GET /invoices

Lister les factures (clé partenaire)

```bash
curl https://hira.localtechstudio.com/api/v1/invoices \
  -H "Authorization: Bearer pk_live_…"
```

### GET /invoices/{id}

Détail d'une facture (clé partenaire)

```bash
curl https://hira.localtechstudio.com/api/v1/invoices/… \
  -H "Authorization: Bearer pk_live_…"
```

### GET /invoices/{id}/pdf

PDF d'une facture payée, numérotée WA-AAAA-NNNNNN (clé partenaire)

```bash
curl https://hira.localtechstudio.com/api/v1/invoices/…/pdf \
  -H "Authorization: Bearer pk_live_…"
```

### POST /billing/checkout

Démarrer un paiement. XAF/XOF/KES → pawaPay (`phone` international, 202). EUR/USD → Stripe Checkout (`payment.checkoutUrl`, 201, `phone` interdit). Activation à la confirmation (callback pawaPay / webhook Stripe), idempotente.

- `plan`: string
- `interval`: monthly | yearly
- `currency`: XAF | XOF | KES | EUR | USD
- `extraNumbers`: integer
- `phone`: string
- `successUrl`: string
- `cancelUrl`: string

```bash
curl -X POST https://hira.localtechstudio.com/api/v1/billing/checkout \
  -H "Authorization: Bearer pk_live_…" \
  -H "Content-Type: application/json" \
  -d '{"plan":"string","interval":"monthly","currency":"XAF","extraNumbers":0,"phone":"string","successUrl":"string","cancelUrl":"string"}'
```

