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 The response carries the initial
variable_examples. The first item is the example of {{1}}.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 fortemplate.approved,template.rejectedortemplate.failed. - Querying: call
GET /v1/templates/{id}and checkstatus.
- If the template is rejected (
rejected),rejection_reasongives 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_codegives the reason, andfailure_detailcarries 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 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.
approved, pass template.id and the body_parameters in the order of the placeholders.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 isOrder {{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}}.
indexis the position of the button incomponents.buttons, starting at 0. Every button counts, of any kind. In the example, the quick reply is button0, so the URL button is1.textreplaces only the{{1}}of the URL. Do not send the whole URL.- Routa appends
textto 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 withPOST /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 must belong to this project and be
ready. - A file received from a contact is refused. Upload it again with
POST /v1/mediaand use the newid. filenameis 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
failedwithfailure_code: media_unavailable.
Refused values
The API refuses at accept time, with422 content_rejected:
- A missing or extra parameter, a repeated
index, or an item for a button that has no variable. textandmedia_idtogether,media_idon a text header,texton a media header, orfilenameoutside a document header.- An empty or blank header
text,media_idorfilename, or buttontext. - A
body_parametersvalue 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.