Send messages
Send WhatsApp text messages, reply buttons, lists, link buttons, approved templates and media from your own system.
Three endpoints send messages: /api/send for text and interactive messages, /api/send/template for approved templates, and /api/send/media for files. Every message you send this way also appears in the chat in your ZAPGEN inbox, so your team sees it.
Before you send#
- WhatsApp must be connected in Settings › WhatsApp. Otherwise you get
403withPlease setup your whatsapp account!. - The 24-hour rule. WhatsApp only lets you send free-form messages (text, buttons, lists, media) within 24 hours of the customer's last message to you. Outside that window, send an approved template. See The 24-hour window.
- New numbers become contacts. If the phone number isn't a contact yet, ZAPGEN creates one. Add
first_name,last_nameandemailto the request to fill them in.
Send a message#
https://app.zapgen.ae/api/sendSends a text message. Add buttons, sections or ctaUrlButton to turn it into an interactive message.
| Name | Type | Required | Description |
|---|---|---|---|
phone | string | Yes | The customer's number with country code, e.g. +971501234567. |
message | string | Yes | The message text. For interactive messages it's the body text. Links show a preview. WhatsApp formatting like *bold* and _italic_ works. |
buttons | array | No | Up to 3 reply buttons: [{"id": "…", "title": "…"}]. |
sections | array | No | A list menu (see Send a list). Needs buttonLabel. |
buttonLabel | string | With sections | The text on the button that opens the list. |
ctaUrlButton | object | No | A button that opens a website: {"display_text": "…", "url": "https://…"}. |
header | string | No | Bold header text above an interactive message. |
footer | string | No | Small grey text under an interactive message. |
first_name, last_name, email | string | No | Used only when the number isn't a contact yet. |
header and footer only apply to interactive messages. If you send more than one of sections, ctaUrlButton and buttons, ZAPGEN uses the first one in that order.
Send text#
curl -X POST https://app.zapgen.ae/api/send \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"phone": "+971501234567",
"message": "Hi Sara, your order #4421 is ready for pickup at Kava Coffee JLT."
}'const res = await fetch('https://app.zapgen.ae/api/send', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: JSON.stringify({
phone: '+971501234567',
message: 'Hi Sara, your order #4421 is ready for pickup at Kava Coffee JLT.'
})
});
const result = await res.json();
if (!result.data.success) console.error(result.data.message);$ch = curl_init('https://app.zapgen.ae/api/send');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
'Accept: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'phone' => '+971501234567',
'message' => 'Hi Sara, your order #4421 is ready for pickup at Kava Coffee JLT.',
]),
]);
$result = json_decode(curl_exec($ch), true);
if (!$result['data']['success']) {
error_log($result['data']['message']);
}import requests
res = requests.post(
"https://app.zapgen.ae/api/send",
headers={"Authorization": "Bearer YOUR_API_KEY", "Accept": "application/json"},
json={
"phone": "+971501234567",
"message": "Hi Sara, your order #4421 is ready for pickup at Kava Coffee JLT.",
},
)
result = res.json()
if not result["data"]["success"]:
print(result["data"]["message"])Send reply buttons#
Up to 3 buttons the customer can tap instead of typing. Meta limits button titles to 20 characters. When the customer taps one, its title arrives as their reply, and its id comes with the message.received webhook.
{
"phone": "+971501234567",
"header": "Your booking",
"message": "Can you make it to your facial on Saturday at 14:30?",
"footer": "Glow Studio",
"buttons": [
{ "id": "confirm", "title": "Yes, I'll be there" },
{ "id": "reschedule", "title": "Change the time" }
]
}Send a list#
A button that opens a menu of options, grouped in sections. Meta allows up to 10 rows in total, row titles up to 24 characters and descriptions up to 72.
{
"phone": "+971501234567",
"message": "What would you like to order?",
"buttonLabel": "See the menu",
"sections": [
{
"title": "Coffee",
"rows": [
{ "id": "flat-white", "title": "Flat white", "description": "AED 18" },
{ "id": "spanish-latte", "title": "Spanish latte", "description": "AED 22" }
]
},
{
"title": "Bakery",
"rows": [
{ "id": "croissant", "title": "Butter croissant", "description": "AED 12" }
]
}
]
}Send a link button#
One button that opens a web page.
{
"phone": "+971501234567",
"header": "New collection",
"message": "Our autumn collection is live. Take a look before it sells out.",
"footer": "Kava Coffee",
"ctaUrlButton": {
"display_text": "Shop now",
"url": "https://example.com/autumn"
}
}displayText is accepted as well as display_text.
Response#
{
"statusCode": 200,
"contact": {
"uuid": "4d1f7a3e-9b2c-4c41-8f0e-2a7d5c9b1e63",
"phone": "+971501234567"
},
"data": {
"success": true,
"data": {
"messaging_product": "whatsapp",
"contacts": [{ "input": "+971501234567", "wa_id": "971501234567" }],
"messages": [{ "id": "wamid.HBgMOTcxNTAxMjM0NTY3FQIAERgSQjM0RkE2QTk0RTg4MkQ0NzhBAA==" }],
"chat": { "uuid": "b6f0c2d8-3a91-4f57-a3c4-0d2e8b7c6a15", "type": "outbound" }
}
}
}data.successtells you whether Meta accepted the message.data.data.messages[0].idis WhatsApp's message ID (thewamid). Store it to match the delivery and read updates from themessage.status.updatewebhook.data.data.chatis the message as saved in the ZAPGEN chat. Its fields may change, so don't depend on them.
When Meta refuses the message straight away, the status is still 200, data.success is false, data.message holds Meta's reason and data.data.error holds Meta's full error:
{
"statusCode": 200,
"contact": { "uuid": "4d1f7a3e-…", "phone": "+971501234567" },
"data": {
"success": false,
"message": "(#131009) Parameter value is not valid",
"data": {
"error": {
"message": "(#131009) Parameter value is not valid",
"type": "OAuthException",
"code": 131009,
"error_data": {
"messaging_product": "whatsapp",
"details": "Button title length invalid. Min length: 1, Max length: 20"
}
}
}
}
}Some problems only show up after Meta has accepted the message (success: true). Meta then reports the message as failed in a message.status.update webhook, for example when the 24-hour window has closed (131047) or the message couldn't be delivered to that number (131026). Meta lists all its codes in WhatsApp Cloud API error codes.
Send a template#
https://app.zapgen.ae/api/send/templateSends an approved message template. Templates are the only messages you can send outside the 24-hour window, so use them for order updates, reminders and anything the customer didn't just ask for.
| Name | Type | Required | Description |
|---|---|---|---|
phone | string | Yes | The customer's number with country code. |
template | object | Yes | Passed to Meta as-is, in Meta's template message format. |
template.name | string | Yes | The template name, e.g. order_ready. |
template.language | object | Yes | The template's language as an object, e.g. {"code": "en_US"}. A plain string isn't accepted by Meta. |
template.components | array | If the template has variables | Values for the header, body variables and buttons. |
first_name, last_name, email | string | No | Used only when the number isn't a contact yet. |
In Templates, open the menu next to an approved template and choose Copy API payload. You get a ready request body with the exact name, language code and one placeholder for every variable. Replace the <…> placeholders and send it.

The template must be approved by Meta, and the name and language code must match it exactly. If you created it in Meta's WhatsApp Manager, click Sync templates in ZAPGEN first: a template that isn't synced still goes out, but the chat in ZAPGEN only shows its name instead of the full message.
This example fills {{1}} in the body with an order number and the end of a website button's link:
curl -X POST https://app.zapgen.ae/api/send/template \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"phone": "+971501234567",
"template": {
"name": "order_ready",
"language": { "code": "en_US" },
"components": [
{ "type": "body", "parameters": [{ "type": "text", "text": "#4421" }] },
{ "type": "button", "sub_type": "url", "index": "0",
"parameters": [{ "type": "text", "text": "4421" }] }
]
}
}'const res = await fetch('https://app.zapgen.ae/api/send/template', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: JSON.stringify({
phone: '+971501234567',
template: {
name: 'order_ready',
language: { code: 'en_US' },
components: [
{ type: 'body', parameters: [{ type: 'text', text: '#4421' }] },
{ type: 'button', sub_type: 'url', index: '0', parameters: [{ type: 'text', text: '4421' }] }
]
}
})
});
const result = await res.json();$payload = [
'phone' => '+971501234567',
'template' => [
'name' => 'order_ready',
'language' => ['code' => 'en_US'],
'components' => [
['type' => 'body', 'parameters' => [['type' => 'text', 'text' => '#4421']]],
['type' => 'button', 'sub_type' => 'url', 'index' => '0',
'parameters' => [['type' => 'text', 'text' => '4421']]],
],
],
];
$ch = curl_init('https://app.zapgen.ae/api/send/template');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
'Accept: application/json',
],
CURLOPT_POSTFIELDS => json_encode($payload),
]);
$result = json_decode(curl_exec($ch), true);import requests
payload = {
"phone": "+971501234567",
"template": {
"name": "order_ready",
"language": {"code": "en_US"},
"components": [
{"type": "body", "parameters": [{"type": "text", "text": "#4421"}]},
{"type": "button", "sub_type": "url", "index": "0",
"parameters": [{"type": "text", "text": "4421"}]},
],
},
}
res = requests.post(
"https://app.zapgen.ae/api/send/template",
headers={"Authorization": "Bearer YOUR_API_KEY", "Accept": "application/json"},
json=payload,
)
result = res.json()A template with an image header takes the image in a header component:
{ "type": "header", "parameters": [{ "type": "image", "image": { "link": "https://example.com/offer.jpg" } }] }The response has the same shape as above. Check data.success: for example, sending the wrong number of variables for the template (132000) comes back as success: false.
Send media#
https://app.zapgen.ae/api/send/mediaSends a file from a public URL. WhatsApp downloads the file from your link, so it must be reachable from the internet without a login.
| Name | Type | Required | Description |
|---|---|---|---|
phone | string | Yes | The customer's number with country code. |
media_type | string | Yes | image, video, audio, document or sticker. |
media_url | string | Yes | A public https:// link to the file. |
caption | string | No | Text under an image, video or document (up to 1,024 characters). Ignored for audio and stickers. |
file_name | string | No | The file name the customer sees for a document. Defaults to the name at the end of media_url. |
first_name, last_name, email | string | No | Used only when the number isn't a contact yet. |
Meta decides which file types and sizes it accepts for each media_type, for example JPEG or PNG images up to 5 MB and PDF documents. See Meta's supported media types.
curl -X POST https://app.zapgen.ae/api/send/media \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-H "Accept: application/json" \
-d '{
"phone": "+971501234567",
"media_type": "document",
"media_url": "https://example.com/invoices/INV-4421.pdf",
"file_name": "Invoice INV-4421.pdf",
"caption": "Here is your invoice. Thank you for your order!"
}'const res = await fetch('https://app.zapgen.ae/api/send/media', {
method: 'POST',
headers: {
Authorization: 'Bearer YOUR_API_KEY',
'Content-Type': 'application/json',
Accept: 'application/json'
},
body: JSON.stringify({
phone: '+971501234567',
media_type: 'document',
media_url: 'https://example.com/invoices/INV-4421.pdf',
file_name: 'Invoice INV-4421.pdf',
caption: 'Here is your invoice. Thank you for your order!'
})
});
const result = await res.json();$ch = curl_init('https://app.zapgen.ae/api/send/media');
curl_setopt_array($ch, [
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_HTTPHEADER => [
'Authorization: Bearer YOUR_API_KEY',
'Content-Type: application/json',
'Accept: application/json',
],
CURLOPT_POSTFIELDS => json_encode([
'phone' => '+971501234567',
'media_type' => 'document',
'media_url' => 'https://example.com/invoices/INV-4421.pdf',
'file_name' => 'Invoice INV-4421.pdf',
'caption' => 'Here is your invoice. Thank you for your order!',
]),
]);
$result = json_decode(curl_exec($ch), true);import requests
res = requests.post(
"https://app.zapgen.ae/api/send/media",
headers={"Authorization": "Bearer YOUR_API_KEY", "Accept": "application/json"},
json={
"phone": "+971501234567",
"media_type": "document",
"media_url": "https://example.com/invoices/INV-4421.pdf",
"file_name": "Invoice INV-4421.pdf",
"caption": "Here is your invoice. Thank you for your order!",
},
)
result = res.json()The response has the same shape as above. media_url must be a public internet address: links to private or internal networks are refused with a 400.
Errors#
| Status | When |
|---|---|
200 with data.success: false | Meta refused the message. See data.message. |
200, then a failed status | Meta accepted the message but couldn't deliver it. You'll get a message.status.update webhook. |
400 | A required field is missing, the phone number isn't valid, media_type isn't one of the allowed values, or media_url isn't a public link. |
401 | The API key is missing or wrong. |
403 | WhatsApp isn't connected, or your subscription has ended. |
429 | More than 600 requests in a minute. |