Send a message
Send a WhatsApp message to a phone number: an approved template, a text reply, a file or a message with buttons. If the number isn't a contact yet, the contact and its conversation are created, and the message shows in your inbox like any other.
/api/v1/messagesNeeds the scope messages:send
Templates first, free text within 24 hours
meta_error.Body#
A JSON object. Only the fields for the message type you send are used.
tostringRequiredThe customer's phone number in international format, for example+919876543210.typestringoptionalOne oftext,template,image,video,document,audioorinteractive. Default:text.textstringoptionalThe message fortext(required there), or the caption for an image, video or document (up to 1,024 characters).templateobjectoptionalRequired whentypeistemplate. The template must be approved by Meta and synced in CAT Engage. List templates tells you the names and exactly which values each one needs.namestringRequiredThe template name, for example order_update.languagestringoptionalLanguage code such asen_US. Leave it out to use the approved template with that name.paramsstring[] | objectoptionalThe values for the template's variables. A list fills the body in order ({{1}},{{2}}…). For more, send an object:body(list),headerText,headerMediaUrl(an https link) andbuttonParams(button index to value, for example{ "0": "A-1042" }).
media_urlstringoptionalRequired forimage,video,documentandaudio. A publichttps://link to the file.filenamestringoptionalThe file name the customer sees, for documents. For example invoice.pdf.interactive_payloadobjectoptionalRequired forinteractive. Up to 3 reply buttons, or a list of up to 10 rows. When the customer taps one, itsidcomes back asinteractive_reply_idin themessage.receivedwebhook.kind"buttons" | "list"RequiredWhich layout to send.bodystringRequiredThe message text above the buttons or list (up to 1,024 characters).headerstringoptionalOptional plain-text header (up to 60 characters).footerstringoptionalOptional grey footer line (up to 60 characters).buttonsobject[]optionalForbuttons: 1 to 3 items of{ id, title }. Titles up to 20 characters.button_labelstringoptionalForlist: the label of the button that opens the list (up to 20 characters).sectionsobject[]optionalForlist: sections of{ title?, rows: [{ id, title, description? }] }, 10 rows in total at most.
reply_to_message_idstringoptionalQuote an earlier message in the same conversation (our message id).namestringoptionalA name for the contact, used only when this number is new.
Examples#
Template with a variable
Fills {{1}} in the template body with the order number.
curl -X POST https://app.catengage360.com/api/v1/messages \
-H "Authorization: Bearer cat_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"to": "+919876543210",
"type": "template",
"template": {
"name": "order_update",
"language": "en_US",
"params": [
"A-1042"
]
}
}'Text reply
curl -X POST https://app.catengage360.com/api/v1/messages \
-H "Authorization: Bearer cat_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"to": "+919876543210",
"text": "Your order is out for delivery and will reach you by 6 pm."
}'Document with a caption
curl -X POST https://app.catengage360.com/api/v1/messages \
-H "Authorization: Bearer cat_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"to": "+919876543210",
"type": "document",
"media_url": "https://example.com/invoices/A-1042.pdf",
"filename": "Invoice A-1042.pdf",
"text": "Here is your invoice."
}'Reply buttons
curl -X POST https://app.catengage360.com/api/v1/messages \
-H "Authorization: Bearer cat_live_your_key_here" \
-H "Content-Type: application/json" \
-d '{
"to": "+919876543210",
"type": "interactive",
"interactive_payload": {
"kind": "buttons",
"body": "Would you like to confirm your appointment for Friday at 11 am?",
"buttons": [
{
"id": "confirm",
"title": "Confirm"
},
{
"id": "reschedule",
"title": "Reschedule"
}
]
}
}'Response#
201Message sent to WhatsApp
{
"data": {
"message_id": "0f6b1c52-8d0e-4b8c-9a51-3f1e2d7c9a10",
"whatsapp_message_id": "wamid.HBgMOTE5ODc2NTQzMjEwFQIAERgS…",
"conversation_id": "5d2a9e47-1c3b-4f6e-8a20-7b9c1d4e6f81",
"contact_id": "a81c3f09-2e5d-4b7a-9c64-0d1e2f3a4b5c",
"contact_created": false
}
}Keep whatsapp_message_id: delivery updates (sent, delivered, read, failed) arrive with it in the message.status_updated webhook. contact_created is true when this number was new.
403Account not approved yet
{
"error": {
"code": "account_not_approved",
"message": "Your account is waiting for approval. You can send messages once it is approved."
}
}Errors#
Branch on error.code. The message explains what went wrong in plain words.
| Code | Status | What it means |
|---|---|---|
bad_request | 400 | A field is missing or invalid, for example no to, no text for a text message, or a media link that isn't https. |
template_not_found | 400 | No template with that name. Sync templates from Meta in Settings, then try again. |
template_not_approved | 400 | The template exists but Meta hasn’t approved it, or it is paused or disabled. |
whatsapp_not_configured | 400 | WhatsApp is not connected for this business, or needs reconnecting. |
unauthorized | 401 | The API key is missing, wrong, revoked or expired. |
forbidden | 403 | The key doesn't have the messages:send scope. |
account_not_approved | 403 | The business is waiting for approval. Reads and contacts work; sending starts after approval. |
account_suspended | 403 | Messaging is paused for this business. |
plan_limit | 403 | The number is new and the plan’s contact limit is reached. |
rate_limited | 429 | More than 120 requests a minute with this key. Wait for the seconds in Retry-After. |
meta_error | 502 | WhatsApp refused the message, for example free text outside the 24-hour window. The message includes Meta’s reason. |
Sending to many people?