Skip to main content
Use a template to send a message approved by WhatsApp, with variable values you fill in. To understand the approval cycle, see Templates.
Required scopes: templates:write to create, templates:read to retrieve and messages:write to send. For a media header, you also need media:write.
1

Create the template

Send one example for each variable in variable_examples. The first item is the example of {{1}}.
Use made-up values in the examples, never real personal data or a real token. They are stored with the template, returned by the API and sent in events and webhooks.
The response carries the initial status and variables, with the index and the example of each body variable. A text header or a URL button with a variable also requires its own example. Without the example of a variable, the API responds 422 template_variables_invalid. See Variable examples.language is the code WhatsApp uses, such as en_US or pt_BR, with an underscore and not a hyphen.
2

Wait for approval

The provider decides in its own time. Follow it in one of two ways:
  • Webhook: subscribe to template.* and wait for template.approved, template.rejected or template.failed.
  • Querying: call GET /v1/templates/{id} and check status.
  • If the template is rejected (rejected), rejection_reason gives the reason. Fix it and create another template with a different name, or edit the template in the dashboard.
  • If sending it for approval fails (failed), Routa could not send the template to the provider. failure_code gives the reason, and failure_detail carries the provider’s sentence, when there is one. Through the API, you do not resend it: create the template again. In the dashboard, you can edit it and send it again. See When sending for approval fails.
3

Send with parameters

With the template approved, pass template.id and the body_parameters in the order of the placeholders.
If the header or a button of the template has a variable, or if the header is media, also send the fields in Header and buttons.

Header and buttons

A send carries exactly what the template asks for, on every send: To find out what a template asks for, retrieve it with GET /v1/templates/{id} and read variables and components.

Text in the header and values in the buttons

In this example, the header is Order {{1}}, the body is Hi {{1}}, invoice {{2}} is here., the first button is a quick reply and the second one opens https://example.com/invoices/{{1}}.
  • index is the position of the button in components.buttons, starting at 0. Every button counts, of any kind. In the example, the quick reply is button 0, so the URL button is 1.
  • text replaces only the {{1}} of the URL. Do not send the whole URL.
  • Routa appends text to the URL exactly as it arrives. Percent-encode it first, only once: a space becomes %20, and é becomes %C3%A9. In Node.js, encodeURIComponent() works for a path segment or a query value. The SDK does not encode for you.

File in the header

For a media header, upload the file with POST /v1/media and use its id (med_...) in header_parameter.media_id. You name the file on every send. The sample used to create the template (tmedia_..., from POST /v1/templates/media) is not reused.
The file type must match the header format:
  • The file must belong to this project and be ready.
  • A file received from a contact is refused. Upload it again with POST /v1/media and use the new id.
  • filename is the name the recipient sees. It only applies to a document header.
  • If the file becomes unavailable before sending, for example because media retention expired, the message ends up failed with failure_code: media_unavailable.

Refused values

The API refuses at accept time, with 422 content_rejected:
  • A missing or extra parameter, a repeated index, or an item for a button that has no variable.
  • text and media_id together, media_id on a text header, text on a media header, or filename outside a document header.
  • An empty or blank header text, media_id or filename, or button text.
  • A body_parameters value or header text with a line break, a tab or more than 4 spaces in a row.
  • A button value with any character outside visible ASCII, such as a space, a line break, an accented letter or an emoji.
message says which field failed and never repeats the value. A refused request stores no message and uses none of your allowance.
The values you send are kept in the message content and travel in events and webhooks, filename included.

Validation rules

Routa validates the template at accept time, so these errors come back right away: When you create the template, Routa also refuses right away a name, a body, a header or buttons WhatsApp would reject, and a variable with no example (template_name_invalid, template_variables_invalid and template_components_invalid). See Validation rules at accept time.
In the SDK, variableExamples, example, headerParameter and buttonParameters exist from version 0.5.0. An earlier version does not send the examples, and the API refuses the submit() of a template with a variable. See Upgrade the SDK. components and templates.uploadMedia() exist since 0.3.0. See Templates in the SDK and Rich components.