> ## 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.

# Envoyer un message texte

> Envoyez un message texte simple à un contact WhatsApp

### Endpoint

<ParamField method="POST" path="/v1/whatsapp/messages/send" />

### Headers

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

### Body Parameters

<ParamField body="data.accountId" type="string" required>
  ID du compte WhatsApp
</ParamField>

<ParamField body="data.to" type="string" required>
  Numéro destinataire (format international)
</ParamField>

<ParamField body="data.type" type="string" required>
  Type de message (doit être "text")
</ParamField>

<ParamField body="data.content" type="string" required>
  Contenu du message texte
</ParamField>

<ParamField body="data.buttons" type="array">
  Jusqu’à trois boutons interactifs. Consultez [Boutons interactifs](/fr/messages/interactive-buttons).
</ParamField>

<ParamField body="data.footerText" type="string">
  Pied affiché sous les boutons, limité à 60 caractères. Il est ignoré si `buttons` est absent ou vide.
</ParamField>

<ParamField body="data.isCampaign" type="boolean">
  Marquer comme message de campagne
</ParamField>

<ParamField body="data.campaignId" type="string">
  ID de la campagne (si isCampaign=true)
</ParamField>

### Exemples de requêtes

<CodeGroup>
  ```bash BASH theme={null}
  curl -X POST https://api.wachap.com/v1/whatsapp/messages/send \
    -H "Content-Type: application/json" \
    -H "Authorization: Bearer token" \
    -d '{
      "data": {
        "accountId": "a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878",
        "to": "+33612345678",
        "type": "text",
        "content": "Souhaitez-vous confirmer ?",
        "buttons": [
          {"id": "yes", "text": "Oui", "type": "reply"},
          {"id": "site", "text": "Voir le site", "type": "url", "url": "https://wachap.com"}
        ],
        "footerText": "WaChap"
      }
    }'
  ```

  ```javascript JAVASCRIPT theme={null}
  const response = await fetch('https://api.wachap.com/v1/whatsapp/messages/send', {
    method: 'POST',
    headers: {
      'Authorization': 'Bearer token',
      'Content-Type': 'application/json'
    },
    body: JSON.stringify({
      data: {
        accountId: 'a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878',
        to: '+33612345678',
        type: 'text',
        content: 'Souhaitez-vous confirmer ?',
        buttons: [
          { id: 'yes', text: 'Oui', type: 'reply' },
          { id: 'site', text: 'Voir le site', type: 'url', url: 'https://wachap.com' }
        ],
        footerText: 'WaChap'
      }
    })
  });

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

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

  url = "https://api.wachap.com/v1/whatsapp/messages/send"
  headers = {
      "Authorization": "Bearer token",
      "Content-Type": "application/json"
  }
  payload = {
      "data": {
          "accountId": "a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878",
          "to": "+33612345678",
          "type": "text",
          "content": "Souhaitez-vous confirmer ?",
          "buttons": [
              {"id": "yes", "text": "Oui", "type": "reply"},
              {"id": "call", "text": "Nous appeler", "type": "call", "phoneNumber": "+2290100000000"}
          ],
          "footerText": "WaChap"
      }
  }

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

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

  $payload = [
      "data" => [
          "accountId" => "a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878",
          "to" => "+33612345678",
          "type" => "text",
          "content" => "Souhaitez-vous confirmer ?",
          "buttons" => [
              ["id" => "yes", "text" => "Oui", "type" => "reply"],
              ["id" => "site", "text" => "Voir le site", "type" => "url", "url" => "https://wachap.com"]
          ],
          "footerText" => "WaChap"
      ]
  ];

  curl_setopt_array($curl, [
    CURLOPT_URL => "https://api.wachap.com/v1/whatsapp/messages/send",
    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": "Message envoyé avec succès",
  "messageId": "3EB0123456789ABCDEF",
  "timestamp": 1702000000
}
```

### Codes d'erreur

| Code  | Description                                                    |
| :---- | :------------------------------------------------------------- |
| `400` | MISSING\_ACCOUNT\_ID - accountId manquant                      |
| `400` | MISSING\_TO - Numéro destinataire manquant                     |
| `400` | MISSING\_TYPE - Type de message manquant                       |
| `400` | MISSING\_CONTENT - Contenu du message manquant                 |
| `400` | SEND\_ERROR - Boutons invalides (limite, texte, URL ou numéro) |
| `401` | INVALID\_SECRET\_KEY - Clé secrète invalide                    |
| `404` | ACCOUNT\_NOT\_FOUND - Compte WhatsApp non trouvé               |
| `429` | MESSAGE\_LIMIT\_REACHED - Limite de messages atteinte          |


## OpenAPI

````yaml POST /whatsapp/messages/send
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:
  /whatsapp/messages/send:
    post:
      tags:
        - Messages
      summary: Envoyer un message
      description: >-
        Envoyer un message (Texte, Image, Audio, Vidéo, Document, Location,
        Contact).
      operationId: sendWhatsAppMessage
      requestBody:
        required: true
        content:
          application/json:
            schema:
              type: object
              required:
                - data
              properties:
                data:
                  type: object
                  required:
                    - accountId
                    - to
                    - type
                  properties:
                    accountId:
                      type: string
                    to:
                      type: string
                    type:
                      type: string
                      enum:
                        - text
                        - image
                        - audio
                        - video
                        - document
                        - location
                        - contact
                    content:
                      type: string
                    imageUrl:
                      type: string
                    audioUrl:
                      type: string
                    videoUrl:
                      type: string
                    documentUrl:
                      type: string
                    filename:
                      type: string
                    caption:
                      type: string
                    buttons:
                      type: array
                      minItems: 1
                      maxItems: 3
                      description: Boutons disponibles pour text, image, video et document.
                      items:
                        $ref: '#/components/schemas/InteractiveButton'
                    footerText:
                      type: string
                      maxLength: 60
                      description: >-
                        Pied facultatif, utilisé uniquement lorsque buttons est
                        non vide.
                    latitude:
                      type: number
                    longitude:
                      type: number
                    name:
                      type: string
                    address:
                      type: string
                    contact:
                      type: object
                      properties:
                        fullName:
                          type: string
                        phoneNumber:
                          type: string
                        organization:
                          type: string
            examples:
              text:
                summary: Message texte
                value:
                  data:
                    accountId: a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878
                    to: '+33612345678'
                    type: text
                    content: Souhaitez-vous confirmer ?
                    buttons:
                      - id: 'yes'
                        text: Oui
                        type: reply
                      - id: website
                        text: Voir le site
                        type: url
                        url: https://wachap.com
                    footerText: WaChap
              image:
                summary: Message image
                value:
                  data:
                    accountId: a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878
                    to: '+33612345678'
                    type: image
                    imageUrl: https://example.com/image.jpg
                    caption: Regardez cette image !
                    buttons:
                      - id: details
                        text: Voir les détails
                        type: url
                        url: https://wachap.com/details
              video:
                summary: Message vidéo
                value:
                  data:
                    accountId: a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878
                    to: '+33612345678'
                    type: video
                    videoUrl: https://example.com/video.mp4
                    caption: Ma vidéo
              audio:
                summary: Message audio
                value:
                  data:
                    accountId: a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878
                    to: '+33612345678'
                    type: audio
                    audioUrl: https://example.com/audio.mp3
              document:
                summary: Message document
                value:
                  data:
                    accountId: a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878
                    to: '+33612345678'
                    type: document
                    documentUrl: https://example.com/document.pdf
                    filename: contrat.pdf
                    caption: Consultez le contrat
                    buttons:
                      - id: received
                        text: Bien reçu
                        type: reply
              location:
                summary: Message localisation
                value:
                  data:
                    accountId: a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878
                    to: '+33612345678'
                    type: location
                    latitude: 48.8566
                    longitude: 2.3522
                    name: Tour Eiffel
                    address: Champ de Mars, Paris
              contact:
                summary: Message contact
                value:
                  data:
                    accountId: a1233b-a1233b-a1233b-a1233b-a1233bcdjdg9878
                    to: '+33612345678'
                    type: contact
                    contact:
                      fullName: Jean Dupont
                      phoneNumber: '+33612345678'
                      organization: WaChap Inc
      responses:
        '200':
          description: OK
        '400':
          description: Bad Request
components:
  schemas:
    InteractiveButton:
      type: object
      required:
        - text
      properties:
        id:
          type: string
          description: >-
            Identifiant unique du bouton dans le message. Généré automatiquement
            s’il est omis.
        text:
          type: string
          minLength: 1
          maxLength: 20
          description: Libellé affiché dans WhatsApp.
        type:
          type: string
          enum:
            - reply
            - url
            - call
          default: reply
        url:
          type: string
          format: uri
          pattern: ^https?://
          description: URL HTTP(S) requise pour un bouton de type url.
        phoneNumber:
          type: string
          pattern: ^\+?[1-9][0-9]{5,14}$
          description: Numéro international requis pour un bouton de type call.
      example:
        id: confirm
        text: Confirmer
        type: reply
  securitySchemes:
    BearerAuth:
      type: http
      scheme: bearer
      bearerFormat: JWT

````