Lifecycle
rejected and failed are not the same thing. With rejected, the provider reviewed the template and refused it. With failed, no review happened, because the template never made it through to the provider.
Each change produces an event (template.submitted, template.pending, template.approved, template.rejected, template.paused, template.disabled, template.failed, template.updated, template.deleted). Subscribe to template.* to follow approval without polling the API. The template.category_changed event tells you when the provider changes the category of a template. template.updated tells you a failed or rejected template was edited and sent again, and template.deleted, that it was removed. See Event types.
Template fields
Besidesid, channel, name, language, category, variables, components, status and the reason fields, the template carries:
Rejection reasons
rejection_reason uses a closed set of Routa values, not provider codes.
When sending for approval fails
Routa tries to send the template to the provider up to 5 times, with growing delays between attempts (from 1 minute to 1 hour). Only a temporary provider failure is retried. Any other reason ends the process on the first attempt. When it ends without success, the template becomesfailed and template.failed is produced.
failure_code is filled in only when status is failed. In every other status it is null. It uses a closed set of Routa values, not provider codes.
Through the API, you do not resend a
failed template: create it again with POST /v1/templates. In the dashboard, you can edit and send again a failed or rejected template.
A failed attempt may have reached the provider without Routa seeing the response. In that case, the provider can still answer later, and the template moves from
failed to pending, approved or rejected. Treat failed as a state the provider’s answer can correct.Imported templates
Besides the templates you create through the API, Routa lists the ones that already existed on the WhatsApp side of the channel. These templates are imported, with the status the provider has for them.
The import is silent: it produces no event or webhook, because you did nothing to make the template appear. Call
GET /v1/templates to see what was imported.
unsupported_components uses a closed set of Routa values.
Create a template
POST /v1/templates creates the template and sends it for review. Provide the channel, the name, the language, the category, the body with positional {{1}}, {{2}} variables and an example for each variable.
The response returns the template with
variables (the body placeholders and their examples) and the current status.
Variable examples
WhatsApp reads one example of each variable when it reviews the template. The API requires an example for every variable:
An example cannot be empty or blank. Whatever has no variable takes no example: a media header, a fixed text, a quick reply, a phone button or a fixed URL.
422 template_variables_invalid, and error.param points at the field:
Positions start at 0:
variable_examples.1 is the example of {{2}}, and the number in components.buttons.0.example is the position of the button. The API reports one problem at a time, and error.details.reason says which case it is.
A template created before examples were required, or imported from WhatsApp without them, has no example: the key is absent, and you can still send it. On an imported template, the example is whatever WhatsApp stores, so a button example can be a whole URL.
Rich components
The optionalcomponents field accepts three slots, all optional. When the template is text only, omit components altogether.
Header
For a media header, upload the file first and use the returned
id:
The format is inferred from the
Content-Type of the upload.
This file is the sample WhatsApp reviews. Recipients never receive it: each message names its own file, uploaded with POST /v1/media. See File in the header.
Footer
An object{ "text": "..." } with up to 60 characters.
Buttons
Up to 10 buttons, in the order you send them. Each button text has at most 25 characters.
A component outside these rules returns
422 with the template_components_invalid code. See all the rules in Validation rules at accept time.
Validation rules at accept time
Routa refuses right away, with422, what WhatsApp is already known to refuse, and a variable with no example. Without this, the template would become failed minutes later. When the error carries param, it points at the part to fix.
Passing these rules does not guarantee approval. WhatsApp decides, and can refuse a template for other reasons.
Edit and delete a template
Editing and deleting a template are dashboard actions. The data API does not expose them, but you see their effect in the template fields and in events.Edit
- You can only edit a
failedorrejectedtemplate, including one imported from WhatsApp. A template with a requested deletion cannot be edited. - The edit replaces the category, the body, the examples and every component. Name and language do not change. Every variable needs an example, even on a template that had none.
- The template goes back to
submitted, the refusal reason andfailure_detailare cleared, and thetemplate.updatedevent is produced. From there, the cycle runs as for a new template. - An imported, read-only template stops being
read_onlyafter the edit, because it now has a body and components Routa knows.originstaysprovider.
Delete
Any template can be deleted. What happens depends on whether WhatsApp already has the template:- No provider reference, or
disabled: Routa removes it right away and producestemplate.deleted. - Otherwise: the deletion is requested and the template gets
deletion_requested: true. Meanwhile, it cannot be used to send (template_not_sendable) or edited. When the provider confirms, the template is removed andtemplate.deletedis produced. - If the deletion does not finish, the template goes back to normal with
deletion_requested: false, anddeletion_failure_detailcarries the reason, when the provider gave one. Routa tries a few times before giving up.
disabled template deleted only in Routa can come back on the next sync, if the provider still has it.
Removal by sync (the template no longer exists on WhatsApp) and removal along with a channel produce no event. From then on, a send that cites the template responds template_not_found.
Send a template
With the templateapproved, send it in POST /v1/messages with its id and the placeholder values, in order:
template without text. The number of body_parameters must match the number of body variables.
A template can also ask for header_parameter, when the header is text with a variable or is media, and button_parameters, when a URL button has a variable. See Header and buttons.