Start Free — No Credit Card Required · IntelliReply AI now replies in Arabic and EnglishSee plans →

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 403 with Please 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_name and email to the request to fill them in.

Send a message#

POSThttps://app.zapgen.ae/api/send

Sends a text message. Add buttons, sections or ctaUrlButton to turn it into an interactive message.

NameTypeRequiredDescription
phonestringYesThe customer's number with country code, e.g. +971501234567.
messagestringYesThe message text. For interactive messages it's the body text. Links show a preview. WhatsApp formatting like *bold* and _italic_ works.
buttonsarrayNoUp to 3 reply buttons: [{"id": "…", "title": "…"}].
sectionsarrayNoA list menu (see Send a list). Needs buttonLabel.
buttonLabelstringWith sectionsThe text on the button that opens the list.
ctaUrlButtonobjectNoA button that opens a website: {"display_text": "…", "url": "https://…"}.
headerstringNoBold header text above an interactive message.
footerstringNoSmall grey text under an interactive message.
first_name, last_name, emailstringNoUsed 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."
  }'

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.

Request body
{
  "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.

Request body
{
  "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" }
      ]
    }
  ]
}

One button that opens a web page.

Request body
{
  "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#

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.success tells you whether Meta accepted the message.
  • data.data.messages[0].id is WhatsApp's message ID (the wamid). Store it to match the delivery and read updates from the message.status.update webhook.
  • data.data.chat is 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:

Meta refused the message
{
  "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#

POSThttps://app.zapgen.ae/api/send/template

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

NameTypeRequiredDescription
phonestringYesThe customer's number with country code.
templateobjectYesPassed to Meta as-is, in Meta's template message format.
template.namestringYesThe template name, e.g. order_ready.
template.languageobjectYesThe template's language as an object, e.g. {"code": "en_US"}. A plain string isn't accepted by Meta.
template.componentsarrayIf the template has variablesValues for the header, body variables and buttons.
first_name, last_name, emailstringNoUsed only when the number isn't a contact yet.
Copy the request body from ZAPGEN

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.

Templates list with an approved template's menu open: Edit, Copy API payload and Delete
Templates list with an approved template's menu open: Edit, Copy API payload and Delete

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" }] }
      ]
    }
  }'

A template with an image header takes the image in a header component:

Header image
{ "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#

POSThttps://app.zapgen.ae/api/send/media

Sends a file from a public URL. WhatsApp downloads the file from your link, so it must be reachable from the internet without a login.

NameTypeRequiredDescription
phonestringYesThe customer's number with country code.
media_typestringYesimage, video, audio, document or sticker.
media_urlstringYesA public https:// link to the file.
captionstringNoText under an image, video or document (up to 1,024 characters). Ignored for audio and stickers.
file_namestringNoThe file name the customer sees for a document. Defaults to the name at the end of media_url.
first_name, last_name, emailstringNoUsed 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!"
  }'

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#

StatusWhen
200 with data.success: falseMeta refused the message. See data.message.
200, then a failed statusMeta accepted the message but couldn't deliver it. You'll get a message.status.update webhook.
400A 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.
401The API key is missing or wrong.
403WhatsApp isn't connected, or your subscription has ended.
429More than 600 requests in a minute.
Still stuck?Our team answers on WhatsApp and at [email protected].
Ask us on WhatsApp