# Send an invoice or a receipt as a PDF over WhatsApp

_Yes, with a template whose header is a DOCUMENT: the sample PDF is attached at creation, the real PDF is sent through a public https URL in header_document_url._

Keywords: PDF, send a PDF, PDF invoice, PDF receipt, report card, document, attachment, file, document header, header document, header_document_url, header_document_filename, header_media_base64, application/pdf, ticket, quote, certificate

## Scenario

A customer pays at the counter: you want to send them the receipt or invoice as a PDF on WhatsApp, with a short message.

**Yes.** There is no "free attachment" beyond the 24 h window: the PDF travels in a **template header**. At creation you give a sample PDF (so Meta approves the shape of the message); on each send you give the **https address** of this customer's real PDF.

## Conversation

```text
You      : POST /v1/messages  to=+237690000001  variables=["Awa", "F-2026-0412"]
           header_document_url=https://files.example.com/factures/F-2026-0412.pdf
           header_document_filename=invoice-F-2026-0412.pdf
Awa      : [ invoice-F-2026-0412.pdf ]
           "Hello Awa, here is your invoice F-2026-0412. Thank you for your trust."
```

## Code

1. Create the template. `header_media_base64` is your sample PDF, base64-encoded (the name `header_image_base64` is accepted too); `header_media_mime` says it is a PDF:

```bash
# curl
curl -X POST "https://wa-api.geskap.com/v1/templates" \
  -H "Authorization: Bearer $GESKAP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "facture_pdf",
  "language": "fr",
  "category": "UTILITY",
  "body_text": "Bonjour {{1}}, voici votre facture {{2}}. Merci de votre confiance.",
  "example_values": ["Awa", "F-2026-0412"],
  "header_media_base64": "<VOTRE_PDF_D_EXEMPLE_EN_BASE64>",
  "header_media_mime": "application/pdf"
}'
```

```js
// Node.js
const res = await fetch("https://wa-api.geskap.com/v1/templates", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.GESKAP_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "facture_pdf",
    "language": "fr",
    "category": "UTILITY",
    "body_text": "Bonjour {{1}}, voici votre facture {{2}}. Merci de votre confiance.",
    "example_values": ["Awa", "F-2026-0412"],
    "header_media_base64": "<VOTRE_PDF_D_EXEMPLE_EN_BASE64>",
    "header_media_mime": "application/pdf"
  }),
});
console.log(res.status, await res.json());
```

```php
// PHP
$ch = curl_init("https://wa-api.geskap.com/v1/templates");
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("GESKAP_API_KEY"),
    "Content-Type: application/json",
  ],
  CURLOPT_POSTFIELDS => json_encode([
    "name" => "facture_pdf",
    "language" => "fr",
    "category" => "UTILITY",
    "body_text" => "Bonjour {{1}}, voici votre facture {{2}}. Merci de votre confiance.",
    "example_values" => ["Awa", "F-2026-0412"],
    "header_media_base64" => "<VOTRE_PDF_D_EXEMPLE_EN_BASE64>",
    "header_media_mime" => "application/pdf",
  ]),
]);
$res = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $res;
```

```python
# Python
import os, requests

res = requests.request(
    "POST",
    "https://wa-api.geskap.com/v1/templates",
    headers={"Authorization": f"Bearer {os.environ['GESKAP_API_KEY']}"},
    json={
        "name": "facture_pdf",
        "language": "fr",
        "category": "UTILITY",
        "body_text": "Bonjour {{1}}, voici votre facture {{2}}. Merci de votre confiance.",
        "example_values": ["Awa", "F-2026-0412"],
        "header_media_base64": "<VOTRE_PDF_D_EXEMPLE_EN_BASE64>",
        "header_media_mime": "application/pdf",
    },
    timeout=15,
)
print(res.status_code, res.json())
```

1. Once `APPROVED`, send it with the address of **this** customer's PDF:

```bash
# curl
curl -X POST "https://wa-api.geskap.com/v1/messages" \
  -H "Authorization: Bearer $GESKAP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "to": "+237690000001",
  "template": {
    "name": "facture_pdf",
    "language": "fr",
    "variables": ["Awa", "F-2026-0412"],
    "header_document_url": "https://files.example.com/factures/F-2026-0412.pdf",
    "header_document_filename": "facture-F-2026-0412.pdf"
  },
  "idempotency_key": "facture-pdf-F-2026-0412"
}'
```

```js
// Node.js
const res = await fetch("https://wa-api.geskap.com/v1/messages", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.GESKAP_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "to": "+237690000001",
    "template": {
      "name": "facture_pdf",
      "language": "fr",
      "variables": ["Awa", "F-2026-0412"],
      "header_document_url": "https://files.example.com/factures/F-2026-0412.pdf",
      "header_document_filename": "facture-F-2026-0412.pdf"
    },
    "idempotency_key": "facture-pdf-F-2026-0412"
  }),
});
console.log(res.status, await res.json());
```

```php
// PHP
$ch = curl_init("https://wa-api.geskap.com/v1/messages");
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("GESKAP_API_KEY"),
    "Content-Type: application/json",
  ],
  CURLOPT_POSTFIELDS => json_encode([
    "to" => "+237690000001",
    "template" => [
      "name" => "facture_pdf",
      "language" => "fr",
      "variables" => ["Awa", "F-2026-0412"],
      "header_document_url" => "https://files.example.com/factures/F-2026-0412.pdf",
      "header_document_filename" => "facture-F-2026-0412.pdf",
    ],
    "idempotency_key" => "facture-pdf-F-2026-0412",
  ]),
]);
$res = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $res;
```

```python
# Python
import os, requests

res = requests.request(
    "POST",
    "https://wa-api.geskap.com/v1/messages",
    headers={"Authorization": f"Bearer {os.environ['GESKAP_API_KEY']}"},
    json={
        "to": "+237690000001",
        "template": {
            "name": "facture_pdf",
            "language": "fr",
            "variables": ["Awa", "F-2026-0412"],
            "header_document_url": "https://files.example.com/factures/F-2026-0412.pdf",
            "header_document_filename": "facture-F-2026-0412.pdf",
        },
        "idempotency_key": "facture-pdf-F-2026-0412",
    },
    timeout=15,
)
print(res.status_code, res.json())
```

## Exact rules

| Item | Rule |
|---|---|
| Creation | sample PDF 16 MB at most, `header_media_mime` required whenever there is a file |
| Accepted document types | PDF, text, Word, Excel, PowerPoint |
| Sending | `header_document_url`: a public `https` address (no `localhost`, no private address) |
| Displayed name | `header_document_filename`; defaults to `recu.pdf` |
| One header only | `header_document_url` **or** `header_image_url`, never both (`422`) |

> **Pitfall:** the sample attached at creation is **not** the file you send. It only lets Meta validate the layout. The real PDF goes by URL on each send, and Meta fetches it: the address must be reachable from the Internet at that moment.

> **Pitfall:** without `header_media_mime`, creation is refused with a message asking for the type: it decides whether the header is an image, a document or a video. Set `application/pdf`.

> **Pitfall:** the PDF address can be read by anyone who receives or forwards the message. For a named invoice, serve a hard-to-guess, short-lived link (see [Sensitive data: single-use link and PIN](https://console.geskap.com/docs/donnees-sensibles-lien-pin?lang=en)).

The template is created once; only the PDF and the name change from one send to the next. First send, statuses and errors: [Message a customer who never wrote to you](https://console.geskap.com/docs/ecrire-premier-message?lang=en). An image header works the same way: [Image header](https://console.geskap.com/docs/image-en-tete?lang=en).

_Proof — verified in the API source: api_schemas.py, api_send.py, cloud_api.py._

---

# Envoyer une facture ou un reçu en PDF par WhatsApp

_Oui, avec un template dont l'en-tête est un DOCUMENT : le PDF d'exemple se joint à la création, le vrai PDF s'envoie par une URL https publique dans header_document_url._

Mots-clés: PDF, envoyer un PDF, facture PDF, reçu PDF, bulletin, document, pièce jointe, fichier, en-tête document, header document, header_document_url, header_document_filename, header_media_base64, application/pdf, ticket, devis, attestation

## Scénario

Un client paie au comptoir : vous voulez lui envoyer son reçu ou sa facture en PDF sur WhatsApp, avec un petit message.

**Oui.** Il n'y a pas de « pièce jointe libre » hors des 24 h : le PDF voyage dans l'**en-tête d'un template**. À la création vous donnez un PDF d'exemple (pour que Meta approuve la forme du message) ; à chaque envoi vous donnez l'**adresse https** du vrai PDF de ce client.

## Conversation

```text
Vous    : POST /v1/messages  to=+237690000001  variables=["Awa", "F-2026-0412"]
          header_document_url=https://files.example.com/factures/F-2026-0412.pdf
          header_document_filename=facture-F-2026-0412.pdf
Awa     : [ facture-F-2026-0412.pdf ]
          « Bonjour Awa, voici votre facture F-2026-0412. Merci de votre confiance. »
```

## Code

1. Créez le template. `header_media_base64` est votre PDF d'exemple, encodé en base64 (le nom `header_image_base64` est accepté aussi) ; `header_media_mime` dit que c'est un PDF :

```bash
# curl
curl -X POST "https://wa-api.geskap.com/v1/templates" \
  -H "Authorization: Bearer $GESKAP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "name": "facture_pdf",
  "language": "fr",
  "category": "UTILITY",
  "body_text": "Bonjour {{1}}, voici votre facture {{2}}. Merci de votre confiance.",
  "example_values": ["Awa", "F-2026-0412"],
  "header_media_base64": "<VOTRE_PDF_D_EXEMPLE_EN_BASE64>",
  "header_media_mime": "application/pdf"
}'
```

```js
// Node.js
const res = await fetch("https://wa-api.geskap.com/v1/templates", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.GESKAP_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "name": "facture_pdf",
    "language": "fr",
    "category": "UTILITY",
    "body_text": "Bonjour {{1}}, voici votre facture {{2}}. Merci de votre confiance.",
    "example_values": ["Awa", "F-2026-0412"],
    "header_media_base64": "<VOTRE_PDF_D_EXEMPLE_EN_BASE64>",
    "header_media_mime": "application/pdf"
  }),
});
console.log(res.status, await res.json());
```

```php
// PHP
$ch = curl_init("https://wa-api.geskap.com/v1/templates");
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("GESKAP_API_KEY"),
    "Content-Type: application/json",
  ],
  CURLOPT_POSTFIELDS => json_encode([
    "name" => "facture_pdf",
    "language" => "fr",
    "category" => "UTILITY",
    "body_text" => "Bonjour {{1}}, voici votre facture {{2}}. Merci de votre confiance.",
    "example_values" => ["Awa", "F-2026-0412"],
    "header_media_base64" => "<VOTRE_PDF_D_EXEMPLE_EN_BASE64>",
    "header_media_mime" => "application/pdf",
  ]),
]);
$res = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $res;
```

```python
# Python
import os, requests

res = requests.request(
    "POST",
    "https://wa-api.geskap.com/v1/templates",
    headers={"Authorization": f"Bearer {os.environ['GESKAP_API_KEY']}"},
    json={
        "name": "facture_pdf",
        "language": "fr",
        "category": "UTILITY",
        "body_text": "Bonjour {{1}}, voici votre facture {{2}}. Merci de votre confiance.",
        "example_values": ["Awa", "F-2026-0412"],
        "header_media_base64": "<VOTRE_PDF_D_EXEMPLE_EN_BASE64>",
        "header_media_mime": "application/pdf",
    },
    timeout=15,
)
print(res.status_code, res.json())
```

1. Une fois `APPROVED`, envoyez-le avec l'adresse du PDF de **ce** client :

```bash
# curl
curl -X POST "https://wa-api.geskap.com/v1/messages" \
  -H "Authorization: Bearer $GESKAP_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
  "to": "+237690000001",
  "template": {
    "name": "facture_pdf",
    "language": "fr",
    "variables": ["Awa", "F-2026-0412"],
    "header_document_url": "https://files.example.com/factures/F-2026-0412.pdf",
    "header_document_filename": "facture-F-2026-0412.pdf"
  },
  "idempotency_key": "facture-pdf-F-2026-0412"
}'
```

```js
// Node.js
const res = await fetch("https://wa-api.geskap.com/v1/messages", {
  method: "POST",
  headers: {
    Authorization: `Bearer ${process.env.GESKAP_API_KEY}`,
    "Content-Type": "application/json",
  },
  body: JSON.stringify({
    "to": "+237690000001",
    "template": {
      "name": "facture_pdf",
      "language": "fr",
      "variables": ["Awa", "F-2026-0412"],
      "header_document_url": "https://files.example.com/factures/F-2026-0412.pdf",
      "header_document_filename": "facture-F-2026-0412.pdf"
    },
    "idempotency_key": "facture-pdf-F-2026-0412"
  }),
});
console.log(res.status, await res.json());
```

```php
// PHP
$ch = curl_init("https://wa-api.geskap.com/v1/messages");
curl_setopt_array($ch, [
  CURLOPT_CUSTOMREQUEST => "POST",
  CURLOPT_RETURNTRANSFER => true,
  CURLOPT_HTTPHEADER => [
    "Authorization: Bearer " . getenv("GESKAP_API_KEY"),
    "Content-Type: application/json",
  ],
  CURLOPT_POSTFIELDS => json_encode([
    "to" => "+237690000001",
    "template" => [
      "name" => "facture_pdf",
      "language" => "fr",
      "variables" => ["Awa", "F-2026-0412"],
      "header_document_url" => "https://files.example.com/factures/F-2026-0412.pdf",
      "header_document_filename" => "facture-F-2026-0412.pdf",
    ],
    "idempotency_key" => "facture-pdf-F-2026-0412",
  ]),
]);
$res = curl_exec($ch);
echo curl_getinfo($ch, CURLINFO_HTTP_CODE), " ", $res;
```

```python
# Python
import os, requests

res = requests.request(
    "POST",
    "https://wa-api.geskap.com/v1/messages",
    headers={"Authorization": f"Bearer {os.environ['GESKAP_API_KEY']}"},
    json={
        "to": "+237690000001",
        "template": {
            "name": "facture_pdf",
            "language": "fr",
            "variables": ["Awa", "F-2026-0412"],
            "header_document_url": "https://files.example.com/factures/F-2026-0412.pdf",
            "header_document_filename": "facture-F-2026-0412.pdf",
        },
        "idempotency_key": "facture-pdf-F-2026-0412",
    },
    timeout=15,
)
print(res.status_code, res.json())
```

## Règles exactes

| Élément | Règle |
|---|---|
| Création | PDF d'exemple 16 Mo au plus, `header_media_mime` obligatoire quand il y a un fichier |
| Types de document acceptés | PDF, texte, Word, Excel, PowerPoint |
| Envoi | `header_document_url` : adresse `https` publique (pas de `localhost`, pas d'adresse privée) |
| Nom affiché | `header_document_filename` ; par défaut `recu.pdf` |
| Un seul en-tête | `header_document_url` **ou** `header_image_url`, jamais les deux (`422`) |

> **Piège :** l'exemple joint à la création n'est **pas** le fichier envoyé. Il sert seulement à Meta pour valider le gabarit. Le PDF réel part par URL à chaque envoi, et c'est Meta qui va le chercher : l'adresse doit être joignable depuis Internet à ce moment-là.

> **Piège :** sans `header_media_mime`, la création est refusée avec un message qui demande le type : c'est lui qui décide si l'en-tête est une image, un document ou une vidéo. Mettez `application/pdf`.

> **Piège :** l'adresse du PDF est lisible par quiconque reçoit le message ou la transfère. Pour une facture nominative, servez un lien difficile à deviner et de courte durée (voir [Données sensibles : lien unique et PIN](https://console.geskap.com/docs/donnees-sensibles-lien-pin)).

Le template se crée une fois ; seul le PDF et le nom changent d'un envoi à l'autre. Premier envoi, statuts et erreurs : [Écrire à un client qui ne vous a jamais écrit](https://console.geskap.com/docs/ecrire-premier-message). Un en-tête image suit la même mécanique : [Image en en-tête](https://console.geskap.com/docs/image-en-tete).

_Preuve — vérifié dans le code de l'API : api_schemas.py, api_send.py, cloud_api.py._

Support: WhatsApp +237 6 56 09 88 31 · All recipes: https://wa-api.geskap.com/llms.txt
