Skip to Content
Developer docsBeta

Template variables

Fill a template's body, media header and buttons for each recipient.

Templates have placeholders ({{1}}, {{2}}…) that you fill per recipient. GET /templates tells you exactly which ones a template has:

"variables": {
  "header": { "type": "image", "example": null },
  "body": [
    { "index": 1, "name": "customer.name", "example": "Mona" },
    { "index": 2, "name": null, "example": "EID20" }
  ],
  "buttons": [
    { "index": 0, "type": "url", "variable": true, "example": "EID20" },
    { "index": 1, "type": "quick_reply", "variable": false, "example": null }
  ]
}

And each recipient carries the values:

{
  "phone": "+201001234567",
  "variables": {
    "header": "https://cdn.example.com/eid.jpg",
    "body": ["Mona", "EID20"],
    "buttons": { "0": "EID20" }
  }
}

Body

body is an array in order: the first value fills {{1}}, the second {{2}}, and so on. Send exactly as many values as the template has. name is the variable's name in the template studio, when it has one: a hint of what to put there.

Values are sent exactly as you give them. Mawgood fills nothing in for you, not even the customer's name, so what you send is what the customer reads. WhatsApp's rules for a value are checked before anything is sent: not empty, no new line or tab, no more than four spaces in a row, at most 1,024 characters.

Text headers never have variables in Mawgood, so only a media header (image, video, document) shows up in variables.header. Its value is optional:

  • Leave it out and the template's own file is sent, as from the dashboard.
  • Or give a public HTTPS URL of another file. WhatsApp downloads it when sending.

A template with a text header or no header takes no header value.

Buttons

Every button is listed by its position (index, from 0). variable: true means it needs a value per recipient; example is the template's sample. buttons is an object keyed by that index, only for buttons with variable: true:

Button typeValue
urlWith a variable: the part of the URL after the template's fixed base.
copy_codeThe code the customer copies, up to 15 characters and no spaces.
quick_replyNothing. The customer's tap comes back as a reply.
phone_numberNothing. The button calls the number in the template.
flowNothing. The button opens the template's WhatsApp Flow.

Templates the API can't send

Carousels, catalog and multi-product templates, limited-time offers that count down, and templates Meta moved to authentication aren't listed by GET /templates; sending one answers 422 template_not_supported (details.reason). Send them from the dashboard.

When something is missing

A missing or empty value fails the whole request with 422 missing_variables. A value for a part the template doesn't have, or one WhatsApp would refuse, fails it with 422 validation_failed. details says which recipient (0-based position in recipients), which part, which variable and what's wrong (missing, unexpected or invalid):

{
  "error": {
    "code": "missing_variables",
    "message": "Recipient 2 is missing body variable {{2}}",
    "details": { "recipient": 2, "part": "body", "index": 2, "problem": "missing" }
  }
}

Nothing is sent when the request fails, so fix the list and send it again.

On this page