LemuAIDocs

WhatsApp · 8 min read · For developers

Send a WhatsApp Template

Send an approved WhatsApp template to one phone number from your own system, with values for its variables

Open in ChatGPTOpen in ClaudeMarkdown

Sends one approved WhatsApp template to one phone number from your own system, for example an order update, a payment reminder or a login code. You say which template to send, the number to send it to, and the values for the template's variables. It works like the "send template message" API of WATI, Interakt or AiSensy.

Any approved template can be sent: marketing, utility and authentication. To send to a list of people at once, use a broadcast or a journey in the dashboard instead.

Setup required. Before you can send, your workspace needs:

  • WhatsApp connected under WhatsApp → Setup, with at least one number under WhatsApp → Numbers.
  • An approved template under WhatsApp → Templates.
  • Money in your WhatsApp balance. Recharge under Usage & Plan → Usage & balances.
  • An API key from Settings → API Keys. See Authentication.
POST/api/v1/whatsapp/messages/template

Headers#

NameRequiredDescription
X-API-KeyYesAn API key from your workspace. See Authentication.
Content-TypeYesapplication/json

Request body#

Name the template with template_id, or with template_name and language.

FieldTypeRequiredDescription
tostringYesThe number to send to, with its country code: +919876543210 or 919876543210. Spaces and dashes are fine. A 10-digit number without a country code is refused.
template_idintegerOne of template_id or template_nameLemuAI's id for the template, a number such as 44. Open WhatsApp → Templates and click the template: its side panel shows Template ID with a copy button. It is not the Meta template ID shown next to it.
template_namestringOne of template_id or template_nameThe template's name exactly as shown under WhatsApp → Templates, for example order_shipped.
languagestringWith template_name, when the template has more than one languageThe template's language code, for example en, en_US or hi. en also finds en_US when that is the template's only English version. Ignored with template_id, which already points at one language.
variablesobjectWhen the template has variablesThe values for the template's variables, as text or numbers. See Variables. Up to 100 entries.
header_textstringWhen the template's text header has a variableThe value for the header's variable, up to 60 characters. Templates with named variables can give it in variables instead.
header_media_urlstringWhen the template's header is an image, video or documentA public https:// link to the file. WhatsApp downloads it when it sends the message.
header_filenamestringNoThe file name WhatsApp shows for a document header, for example Invoice-10422.pdf. Default: the file name the link ends in, when it ends in one (…/Invoice-10422.pdf).
button_url_valuestringWhen a link button's address ends with a variableThe part that goes in place of the variable. For a button to https://shop.example.com/track/{{1}}, send SO-10422. For a button made with Count clicks on this button, send the whole page address to open; see Link Click Tracking.
coupon_codestringWhen the template has a copy-code buttonThe code the button copies, up to 15 characters.
product_retailer_idsarray of stringsFor a multi-product templateThe content IDs (SKUs) of the products to show, from your WhatsApp catalog. Up to 30.
thumbnail_product_retailer_idstringNoFor a catalog template: the content ID (SKU) of the product whose photo shows on the message.
fromstringNoWhich of your WhatsApp numbers sends the message, as shown under WhatsApp → Numbers (for example +91 98111 12222). Default: your default number.
referencestringNoYour own id for this message, up to 100 characters, for example your order id. It comes back in the response and in Get a WhatsApp Message.

A field that isn't in this table is refused with 422, so a typo in a field name doesn't go unnoticed.

Variables#

variables holds one value for each variable in the template's header and body. The keys depend on how the template was written:

The template's variables look likeSend
{{1}}, {{2}} (positional){"1": "Priya", "2": "SO-10422"}
{{first_name}}, {{order_id}} (named){"first_name": "Priya", "order_id": "SO-10422"}
An authentication template (login or verification code)The code: {"1": "482913"}, up to 15 characters. It fills the message and the template's copy-code or autofill button.
  • Every variable needs a value. If one is missing, nothing is sent and the error lists the keys to send.
  • "1" and "{{1}}" both work as keys. Numbers are sent as text: 2499 becomes 2499.
  • WhatsApp doesn't allow a new line, a tab or more than four spaces in a row inside a value. Such a value is refused before sending.
  • A text header with a variable takes its value from header_text. In a template with positional variables, the header's {{1}} is separate from the body's {{1}}.
  • Keys the template doesn't use are ignored.

Example request: the template order_shipped has the header "Order {{1}}", the body "Hi {{1}}, your order {{2}} is on its way." and a Track button that opens https://shop.example.com/track/{{1}}.

cURL
curl -X POST https://app.lemuai.com/api/v1/whatsapp/messages/template \
  -H "X-API-Key: lemu_your_api_key" \
  -H "Content-Type: application/json" \
  -d '{
    "to": "+919876543210",
    "template_id": 44,
    "variables": { "1": "Priya", "2": "SO-10422" },
    "header_text": "SO-10422",
    "button_url_value": "SO-10422",
    "reference": "order-10422"
  }'

More examples of the body:

JSON
{
  "to": "919876543210",
  "template_name": "plan_renewal",
  "language": "en",
  "variables": { "first_name": "Priya", "plan": "Growth" }
}
JSON
{
  "to": "+919876543210",
  "template_name": "invoice_ready",
  "language": "en",
  "variables": { "1": "INV-10422" },
  "header_media_url": "https://files.example.com/invoices/INV-10422.pdf",
  "header_filename": "Invoice-10422.pdf",
  "from": "+91 98111 13333"
}
JSON
{
  "to": "+919876543210",
  "template_name": "login_code",
  "language": "en",
  "variables": { "1": "482913" }
}

Response#

200: WhatsApp accepted the message.

JSON
{
  "message_id": 90311,
  "provider_message_id": "wamid.HBgMOTE5ODc2NTQzMjEwFQIAERgSNkQ5QjE0RjU2QzM0RTI3QjdBAA==",
  "status": "sent",
  "to": "+919876543210",
  "contact_id": 5821,
  "template": {
    "id": 44,
    "name": "order_shipped",
    "language": "en",
    "category": "utility"
  },
  "reference": "order-10422"
}
FieldTypeDescription
message_idintegerThe message's id in LemuAI. Pass it to Get a WhatsApp Message to see whether it was delivered and read.
provider_message_idstringWhatsApp's id for the message (wamid…). Get a WhatsApp Message accepts it too.
statusstringAlways sent here: WhatsApp accepted the message. Delivered, read or failed comes later.
tostringThe number it was sent to, in + and digits form.
contact_idintegerThe contact the message belongs to. A contact is created when no contact has this number yet.
templateobjectThe template that was sent: id, name, language and category (marketing, utility or authentication).
referencestring or nullThe reference you sent.

What happens with the message#

  • Cost: each message is paid from your WhatsApp balance at WhatsApp's rate for the template's category and the recipient's country. A message WhatsApp refuses is refunded.
  • Inbox and contact: the message shows in the contact's conversation in the Inbox, labelled API, and in the contact's messages. When the person replies, the reply lands in the same conversation and opens WhatsApp's 24-hour window, like any other reply.
  • Delivery: sent means WhatsApp accepted it. Whether it was delivered or read, or why it failed, shows a few seconds later in Get a WhatsApp Message, in the Inbox and in Contact Messages.
  • Opt-out: a contact who opted out of all messages is never sent anything, and a marketing template isn't sent to a contact who stopped WhatsApp marketing (STOP, Stop promotions or Stop marketing in WhatsApp). Utility and authentication templates still go. The request returns 422 with opted_out.
  • Sending limits: the per-channel limits under Settings → Sending Limits apply to journeys and campaigns, not to this API. Your system decides how often a person gets a message.
  • Marketing templates: WhatsApp limits how many marketing messages one person gets from all businesses. When it holds one back, the message's status becomes failed with WhatsApp's reason.

Errors#

Nothing is charged or sent when the request has a problem. The body is:

JSON
{
  "detail": {
    "error": "missing_values",
    "message": "Missing a value for {{2}}. Send variables: {\"2\": \"...\"}.",
    "missing": ["2"],
    "variables": ["1", "2"]
  }
}

error is a fixed word your code can check. message is a sentence that says what to change. missing_values also lists the missing keys and every key the template takes in variables.

Statusdetail.errorWhen
400whatsapp_not_readyWhatsApp isn't connected, setup isn't finished, payment setup with Meta is still pending, Meta restricted the account, or marketing messages are paused on the sending number. detail.message says which.
400template_not_approvedThe template is pending, rejected, paused or disabled. detail.template_status holds its status.
401The API key is missing or not valid.
402balance_too_lowThe WhatsApp balance is too low. Recharge under Usage & Plan → Usage & balances.
404template_not_foundNo template with this template_id in your workspace, no template with this name on the sending number's WhatsApp account, or no version in this language (detail.languages lists the template's languages).
422template_requiredNeither template_id nor template_name was sent.
422language_requiredtemplate_name matches the template in more than one language. Send language.
422missing_valuesA variable, the header value, header_media_url, button_url_value, coupon_code or product_retailer_ids is missing.
422invalid_valuesA value has a new line, a tab or more than four spaces in a row, is too long, or isn't text or a number, or a click-counting button got something other than a full https:// address.
422invalid_numberto isn't a phone number, or has no country code.
422unknown_from_numberfrom isn't one of your numbers under WhatsApp → Numbers.
422opted_outThe contact opted out of all messages, or stopped WhatsApp marketing and this is a marketing template.
422A field is missing, has the wrong type, or isn't a field of this endpoint. detail is then a list of the fields to fix.
502send_failedWhatsApp refused the message when it was sent. detail.message holds WhatsApp's reason. It shows as failed in the Inbox and is refunded. A number without WhatsApp is usually accepted first and then turns failed in Get a WhatsApp Message.

See Errors for the general error format.