Skip to content

Send a message with the API

Send a text or template WhatsApp message to a phone number, choose the sending number, upload media, avoid duplicate sends with an idempotency key, and check where a message has got to.

POST /messages sends any WhatsApp message type from one of your connected numbers. This article shows a text message, a template message, an image, how to choose the sending number, and how to check a message's status afterwards. New to the API? Start with Send your first message in 5 minutes.

The key needs the messages.send permission. To address a customer by phone number (rather than an existing contact id), it also needs contacts.create. A key made with the Send WhatsApp messages preset has both. To save the customer's details in the same request (contact), the key also needs contacts.update: create it with the Send messages and sync contacts preset. See Create and manage API keys.

The basics

  • Body shape: WhatsApp Cloud API's own message shapes. Set type (text, image, video, audio, document, sticker, location, contacts, interactive, reaction or template) and include the object of the same name.
  • Recipient: to takes one of:
    • A phone number in international format, as a string: "to": "+91XXXXXXXXXX", with the customer's number in place of the X's. It must start with + and the country code, with no space between them ("+ 91 …" is refused). After that, spaces, dashes, dots and brackets are ignored, so "+91 XXXXX-XXXXX" works too. A number without the + is refused rather than guessed at (98XXX XXXXX could be Iran's +98); see to_needs_country_code. If you don't hold that contact yet, it is created.
    • { "contact_id": "…" }: an existing contact's id.
    • { "wa_id": "91XXXXXXXXXX" }: the older form, the phone number as digits only with no leading +, starting with the country code. It still works and also creates the contact.
  • Sending number: from picks which of your WhatsApp numbers sends. Leave it out if your organisation has one number. See Choose the sending number.
  • to in these examples is +91XXXXXXXXXX, which the API refuses, so an example you forget to edit sends nothing. Put the customer's number in its place.
  • Idempotency-Key header (required): a unique value per message you intend to send, 8 to 128 characters of letters, digits, ., _, : or -, starting with a letter or digit. If a request times out, retry with the same key: you get the original message back and the customer does not receive it twice.

Send a text message

Text and other free-form messages are only accepted while the customer's 24-hour window is open: within 24 hours of their last message to you. See The 24-hour window and templates.

bash
curl -X POST https://iconengage.com/api/public/v1/messages \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-shipped" \
  -d '{
    "to": "+91XXXXXXXXXX",
    "type": "text",
    "text": { "body": "Your order #1042 has shipped." }
  }'

The body can be up to 4,096 characters.

Send a template message

Use an approved template to message a customer outside the 24-hour window, or one who has never written to you. Name the template and its language, and fill its variables.

bash
curl -X POST https://iconengage.com/api/public/v1/messages \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-confirmation" \
  -d '{
    "to": "+91XXXXXXXXXX",
    "type": "template",
    "template": {
      "name": "order_confirmation",
      "language": "en",
      "variables": ["Asha", "#1042"]
    }
  }'

You can fill the template in one of two ways, never both:

  • variables: the values, as a list or (since 1.5.0) as an object by name. See below. If the template has a copy-code button, also send coupon_code.
  • components: WhatsApp's own header / body / button form with typed parameters. Use it for currency or date values, or your own quick-reply payloads.

The values are checked against the approved template before the message is accepted. Each value must be non-empty and must not contain a new line, a tab or more than four spaces in a row. If they don't fit, the send is refused with 400 validation_failed and details.reason: template_variables, and details.expected lists what the template takes. See template_variables.

See Template variables and buttons for how variables are set up.

Fill the variables by name

A list fills the variables in order: the first value is {{1}}, the second {{2}}, and so on. An object names each one instead, so the order doesn't matter and a missing value is caught by name.

Positional, as a list:

json
"template": {
  "name": "order_confirmation",
  "language": "en",
  "variables": ["Asha", "#1042"]
}

The same send, by name:

json
"template": {
  "name": "order_confirmation",
  "language": "en",
  "variables": { "first_name": "Asha", "order_id": "#1042" }
}
  • The names are the template's own. A template written with WhatsApp's named variables ({{first_name}}) uses those names. A numbered template's names are 1, 2, …, so { "1": "Asha", "2": "#1042" } works too.
  • A name fills every place the template uses it. To give one place its own value, use its key instead: header.1, body.1 or button[0].1 (the first button's link). Don't give a name and one of its keys together.
  • Give every variable once. An unknown name, a missing one, or the wrong number of values in a list is refused with details.expected, which lists the template's names and keys, plus unknown and missing when you sent names. It never repeats your values.

GET /templates/{template_id} lists every variable with its name, key and sample value. See Start from the template's example.

Give the template's header

If the template has a header with something to fill, send it in template.header, by the template's header format:

Header formatWhat to send
Image, video or document{ "image": { "link": "https://…" } }, or { "image": { "media_id": "…" } } for a file uploaded with POST /media. Use video or document the same way. A document link can also have a filename. You can leave the header out when the template has a default header media.
Location{ "location": { "latitude": 19.076, "longitude": 72.8777, "name": "Andheri store" } }
Text with a variable{ "text": "Diwali sale" }: the header variable's value. variables then gives the rest.
None, or text without a variableNo header
bash
curl -X POST https://iconengage.com/api/public/v1/messages \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-shipped-photo" \
  -d '{
    "to": "+91XXXXXXXXXX",
    "type": "template",
    "template": {
      "name": "order_shipped",
      "language": "en",
      "variables": { "first_name": "Asha", "order_id": "#1042" },
      "header": { "image": { "link": "https://example.com/orders/1042.jpg" } }
    }
  }'

A link is fetched once, when the message is accepted, under the same rules as importing media from a URL (see Upload a file). The header is checked before anything is fetched: a header of another format, or a header for a template that has none, is refused with details.reason: template_header, and details.expected_header says what the template takes. See template_header.

Start from the template's example

GET /templates/{template_id} tells you everything a send needs: the template's header_format, its variables, and example, a complete POST /messages body filled with the sample values the template was approved with. To find a template's id by its name, use GET /templates?name=order_shipped.

Note: A template's sample values are returned to every API key with templates.read, as well as shown to your team. When you write a template, don't use a real customer's details as its samples. See Template variables and buttons.

bash
curl https://iconengage.com/api/public/v1/templates/7d2c… \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY"

The answer, shortened to the parts a send uses:

json
{
  "id": "7d2c…",
  "name": "order_shipped",
  "language": "en",
  "status": "approved",
  "header_format": "image",
  "variables": [
    { "key": "body.first_name", "name": "first_name", "component": "body", "position": 0, "sample": "Asha" },
    { "key": "body.order_id", "name": "order_id", "component": "body", "position": 1, "sample": "#1042" }
  ],
  "example": {
    "to": "+91XXXXXXXXXX",
    "type": "template",
    "template": {
      "name": "order_shipped",
      "language": "en",
      "variables": { "first_name": "Asha", "order_id": "#1042" },
      "header": { "image": { "link": "https://example.com/your-image.jpg" } }
    }
  }
}

Copy example as the body of POST /messages, then change to to your customer's number: +91XXXXXXXXXX is a placeholder, and the API refuses it until you replace it, so an example sent unedited reaches nobody. Then replace any placeholder link with your file's address, and swap the sample values for real ones. A template written with named variables gets them by name; a numbered one gets a list. A variable with no sample shows its key in angle brackets, such as <body.2>, for you to fill.

Choose the sending number

If your organisation has exactly one WhatsApp number that can send, leave from out and that number is used. With more than one, name the number in from, in either form:

  • The number itself, as WhatsApp displays it or as digits: "from": "+1 555-010-0100" or "from": "15550100100". Numbers are compared digit by digit, so the formatting doesn't matter.
  • The number's id from GET /numbers: "from": "109876543210001".
bash
curl -X POST https://iconengage.com/api/public/v1/messages \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-shipped-support" \
  -d '{
    "to": "+91XXXXXXXXXX",
    "from": "+91 XXXXX XXXXX",
    "type": "text",
    "text": { "body": "Your order #1042 has shipped." }
  }'

What happens when from is missing or wrong:

  • Several numbers and no from: 400 validation_failed with details.reason: from_required. details.numbers lists the numbers you can name. See from_required.
  • A from that isn't one of your numbers: 400 validation_failed on from, with details.reason: from_unknown and the same details.numbers. See from_unknown.
  • No number can send: 409 conflict with details.reason: no_connected_phone_number. See no_connected_phone_number.

A send refused because its number is missing or can't send creates no contact and fetches no media. The older phone_number_id field still works and takes the number's id. If you send both phone_number_id and from, they must name the same number.

List your numbers

GET /numbers lists every WhatsApp number of your organisation, oldest first, including the ones that can't send right now. The key needs the channels.read permission, which the Send WhatsApp messages preset includes.

bash
curl https://iconengage.com/api/public/v1/numbers \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY"
json
{
  "items": [
    {
      "id": "109876543210001",
      "display_phone_number": "+91 XXXXX XXXXX",
      "name": "Acme Store",
      "quality_rating": "GREEN",
      "status": "CONNECTED",
      "can_send": true,
      "default": true
    }
  ]
}
FieldMeaning
idThe number's id. from and phone_number_id take it.
display_phone_numberThe number as WhatsApp displays it. from takes this too.
nameThe verified business name customers see, or null until WhatsApp has one
quality_ratingWhatsApp's quality rating: GREEN, YELLOW, RED, UNKNOWN, or null before WhatsApp reports one. See Quality and messaging limits.
statusWhatsApp's status of the number, for example CONNECTED, FLAGGED, PENDING or RESTRICTED. Expect values not listed here.
can_sendWhether a message can be sent from it now (status CONNECTED or FLAGGED)
defaulttrue on the number a send without from uses. Only one number can have it, and only when it is the one number that can send.

Save the customer's details in the same request

Add contact to save the customer's name, custom fields and tags with the message. You don't need a separate POST /contacts first.

json
{
  "to": "+91XXXXXXXXXX",
  "type": "template",
  "template": { "name": "order_update", "language": "en", "variables": ["Asha", "#1042"] },
  "contact": {
    "display_name": "Asha Rao",
    "attributes": { "customer_name": "Asha Rao", "plan": "gold" },
    "tags": ["VIP"]
  }
}
  • If you don't have a contact with that number yet, it is created with these details.
  • If you do, display_name replaces the name, attributes are merged key by key (null clears a key, except a required field, which can't be cleared), and tags are added. An empty display_name changes nothing.
  • attributes keys and types are your organisation's custom fields (GET /contact-fields). An unknown key or a value of the wrong type is refused 400 invalid_field_value and nothing is sent. See invalid_field_value.
  • tags are names your organisation already has (GET /tags).
  • The key needs contacts.update, even for a new number, so the same request never works for a new customer and fails for a returning one. The Send messages and sync contacts preset has it.
  • If two requests with the same Idempotency-Key arrive at the same moment, both may save their contact, and only one message is sent. Send one request per key at a time, and retry only after an answer or a timeout.

contact is not the same as contacts, the message type that sends a contact card.

Required custom fields

A send is never refused because of your organisation's required custom fields. A contact created by a send, with or without contact, holds what you gave it, and can lack a required field. Required fields apply when POST /contacts creates a contact, when a teammate edits one, and to an import's new rows. An update through the API checks only the fields you send. See contact_field_required.

The contact is saved before WhatsApp's own rules are checked. A send refused 409 template_required, window_expired or contact_opted_out has still saved it. A send refused for its body, its number, its template or its contact saves nothing and fetches no link.

At high volume

  • contact adds a contact write to every send that carries it. Send it when the customer's details changed, not with every message.
  • A custom field whose value changes starts any published flow that starts with Contact field changes on that field. If a value moves on every send, such a flow starts on every send. Sending the value the contact already has starts nothing.

The response

A new message is answered 202 Accepted. This means IconEngage has stored the message and will send it. It has not reached WhatsApp yet.

json
{
  "id": "6f1c2e8a-…",
  "conversation_id": "b0e4…",
  "contact_id": "2a7d…",
  "direction": "outbound",
  "type": "template",
  "status": "accepted",
  "template_name": "order_confirmation",
  "text": null,
  "media_id": null,
  "wamid": null,
  "created_at": "2026-10-11T09:30:00Z",
  "sent_at": null,
  "delivered_at": null,
  "read_at": null,
  "failed_at": null,
  "failure_code": null,
  "failure": null
}

Repeating a request with the same Idempotency-Key and the same body returns 200 with the original message in its current state, and sends nothing. The same key with a different body is refused 409 duplicate_request.

Send an image or other media

Media messages (image, video, audio, document, sticker) take exactly one of:

  • link: an https URL that IconEngage fetches once, when the message is accepted.
  • media_id: a file you uploaded earlier with POST /media. Upload once and reuse the id when the same file goes to many people.
bash
curl -X POST https://iconengage.com/api/public/v1/messages \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY" \
  -H "Content-Type: application/json" \
  -H "Idempotency-Key: order-1042-invoice" \
  -d '{
    "to": "+91XXXXXXXXXX",
    "type": "document",
    "document": { "media_id": "c3d9…", "filename": "Invoice-1042.pdf", "caption": "Your invoice" }
  }'

A caption (up to 1,024 characters) is allowed on an image, a video or a document. A filename is allowed on a document only.

Upload a file

bash
curl -X POST https://iconengage.com/api/public/v1/media \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY" \
  -F "[email protected];type=application/pdf"

Or import from a URL:

bash
curl -X POST https://iconengage.com/api/public/v1/media \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "https://example.com/files/Invoice-1042.pdf" }'

The answer is 201 with the file's media_id. Rules:

  • The file's declared type must match its contents, and WhatsApp must support the type.
  • Files can be up to 16 MiB. WhatsApp's per-type limits are checked when you send, for example an image is at most 5 MB.
  • A URL must be public https. IconEngage follows at most 3 redirects and gives up after 30 seconds.
  • An upload counts as 5 requests against your quota.
  • An organisation can run 2 URL imports at once. A third gets 429 rate_limited; wait and retry.

Check a message's status

bash
curl https://iconengage.com/api/public/v1/messages/6f1c2e8a-… \
  -H "Authorization: Bearer $ICONENGAGE_API_KEY"

status moves from accepted to sending, sent (WhatsApp has it), delivered and read, or ends at failed. WhatsApp can fail a message even after sent. When it fails, failure explains why: our code, WhatsApp's provider_code (for example 131042 for a payment problem on the WhatsApp Business Account), WhatsApp's own wording, a plain explanation, and provider_href when WhatsApp offers a link to fix the cause.

Rather than polling, subscribe to the API: message status event. See Event webhooks.

Common refusals

StatuscodeMeaning
400validation_failedA field breaks a WhatsApp rule (for example text too long, wrong media type, missing Idempotency-Key). details.fields names each field.
400validation_failed (details.reason: to_needs_country_code)to is a phone number without + and the country code. Write it in international format, for example +91 XXXXX XXXXX.
400validation_failed (details.reason: from_required)Your organisation has several numbers and the request has no from. details.numbers lists them.
400validation_failed (details.reason: from_unknown)from isn't one of your numbers. details.numbers lists them.
409window_expiredThe 24-hour window is closed. Send a template.
409template_requiredThe customer has never written to this number. Only a template can start the conversation.
400validation_failed (details.reason: template_variables)The variables don't fit the template: the wrong count, or a name it doesn't have or that you left out. details.expected lists them.
400validation_failed (details.reason: template_header)The header doesn't match the template's. details.expected_header says what it takes.
409template_not_approvedNo approved template for this number has this name and language.
409contact_opted_outThe customer has opted out. See Opt-outs and consent and Opt-in and opt-out.
400invalid_field_value (details.reason: unknown_field or invalid_value)A key in contact.attributes isn't one of your contact fields, or its value doesn't fit. details.field names it.
403permission_denied (details.permission: contacts.update)The request has contact and the key can't update contacts.
409conflict (details.reason: phone_number_not_connected)The sending number cannot send right now.
402subscription_restricted, usage_limit_reached, wallet_balance_lowYour plan, allowance or WhatsApp credit balance stops the send. See WhatsApp credits.

Most refusals also carry a fix, one sentence on what to change, and a docs_url that links to how to fix it. For every status code, see Rate limits and errors. If messages are accepted but never arrive, see Messages not delivered.

Still need help?

Write to us at [email protected] and tell us what you were trying to do. Already a customer? Sign in to IconEngage — the same articles are under Help in the app.