> ## Documentation Index
> Fetch the complete documentation index at: https://dev.wachap.com/llms.txt
> Use this file to discover all available pages before exploring further.

# Sauvegarder un contact

> Sauvegarder un contact via FCM sur l'appareil enregistré

### Endpoint

<ParamField method="POST" path="/sms/save-contact" />

### Headers

<ParamField header="Authorization" type="string" required>
  Bearer token avec votre Secret Key (format: `Bearer sk_...`)
</ParamField>

### Body Parameters

<ParamField body="name" type="string" required>
  Nom complet du contact à sauvegarder.
</ParamField>

<ParamField body="phone_number" type="string" required>
  Numéro de téléphone du contact (format international, ex: +1234567890).
</ParamField>

<Note>
  **Note**
  Cette requête permet de synchroniser un contact avec l'appareil mobile enregistré. L'action est déclenchée via Google Firebase Cloud Messaging (FCM).
</Note>

### Exemples de requêtes

<CodeGroup>
  ```bash BASH theme={null}
  curl -X POST https://api.wachap.com/v1/sms/save-contact \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer token" \
    -d '{
      "name": "John Doe",
      "phone_number": "+1234567890"
    }'
  ```

  ```javascript JAVASCRIPT theme={null}
  const response = await fetch('https://api.wachap.com/v1/sms/save-contact', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer token',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      name: 'John Doe',
      phone_number: '+1234567890'
    })
  });

  const data = await response.json();
  console.log(data);
  ```

  ```python PYTHON theme={null}
  import requests

  url = "https://api.wachap.com/v1/sms/save-contact"
  headers = {
      "Authorization": "Bearer token",
      "Content-Type": "application/json"
  }
  payload = {
      "name": "John Doe",
      "phone_number": "+1234567890"
  }

  response = requests.post(url, json=payload, headers=headers)
  print(response.json())
  ```

  ```php PHP theme={null}
  <?php
  $curl = curl_init();

  $payload = [
      "name" => "John Doe",
      "phone_number" => "+1234567890"
  ];

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.wachap.com/v1/sms/save-contact",
    CURLOPT_RETURNTRANSFER => true,
    CURLOPT_POST => true,
    CURLOPT_POSTFIELDS => json_encode($payload),
    CURLOPT_HTTPHEADER => [
      "Authorization: Bearer token",
      "Content-Type: application/json"
    ],
  ]);

  $response = curl_exec($curl);
  curl_close($curl);
  echo $response;
  ?>
  ```
</CodeGroup>

### Exemple de réponse

```json theme={null}
{
  "success": true,
  "message": "Contact sauvegardé avec succès via FCM",
  "data": {
    "contactId": "cnt_789ghi012jkl"
  }
}
```

### Codes d'erreur

| Code  | Description                                              |
| :---- | :------------------------------------------------------- |
| `401` | INVALID\_SECRET\_KEY - Clé secrète invalide ou manquante |
| `400` | MISSING\_PARAMETERS - Nom ou numéro manquant             |
| `500` | FCM\_ERROR - Erreur lors de la synchronisation via FCM   |


## OpenAPI

````yaml POST /sms/save-contact
openapi: 3.0.3
info:
  title: WaChap API
  version: 2.0.0
servers:
  - url: https://api.wachap.com/v1
    description: WaChap API server
security:
  - BearerAuth: []
tags:
  - name: Instances
    description: Créer et gérer des instances WhatsApp
  - name: Webhook
    description: Configuration des webhooks de réception
  - name: Messages
    description: Envoyer des messages WhatsApp
  - name: Comptes
    description: Gérer vos comptes WhatsApp connectés
  - name: SMS
    description: Service SMS de WaChap (V4) via FCM
  - name: Étiquettes WhatsApp
    description: Créer et associer des étiquettes aux conversations WhatsApp
paths:
  /sms/save-contact:
    post:
      tags:
        - SMS
      summary: Sauvegarder un contact
      description: Sauvegarder un contact via FCM sur l'appareil enregistré.
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              properties:
                name:
                  type: string
                  description: Nom du contact
                  example: John Doe
                phone_number:
                  type: string
                  description: Numéro de téléphone du contact
                  example: '+1234567890'
              required:
                - name
                - phone_number
      responses:
        '200':
          description: Contact sauvegardé avec succès
          content:
            application/json:
              schema:
                type: object
                properties:
                  success:
                    type: boolean
                  message:
                    type: string
components:
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````