Skip to main content
A template is a reusable message body that WhatsApp must approve before you can send it. Use templates for messages your business starts, such as order confirmations, reminders and verification codes. You create the template, and Routa sends it for review and follows the result. The provider decides on approval, in its own time. A template belongs to a channel: the same name can be approved on one channel and rejected on another.

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

Besides id, 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 becomes failed 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.
A template with read_only: true appears in the list but cannot be used to send. POST /v1/messages with it returns 422 template_not_sendable. If it is failed or rejected, you can edit it in the dashboard. After the edit, it is no longer read-only. Otherwise, create an equivalent template through the API or use another one.
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.
Do not use real personal data or tokens in examples. No recipient receives them, but they are stored on the template, come back in API responses and travel in events and webhooks.
A missing, extra or empty example returns 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 optional components field accepts three slots, all optional. When the template is text only, omit components altogether.
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. 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, with 422, 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 failed or rejected template, 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 and failure_detail are cleared, and the template.updated event is produced. From there, the cycle runs as for a new template.
  • An imported, read-only template stops being read_only after the edit, because it now has a body and components Routa knows. origin stays provider.

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 produces template.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 and template.deleted is produced.
  • If the deletion does not finish, the template goes back to normal with deletion_requested: false, and deletion_failure_detail carries the reason, when the provider gave one. Routa tries a few times before giving up.
Under the provider’s rules, an approved template that was deleted cannot be created again with the same name for 30 days. A 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 template approved, send it in POST /v1/messages with its id and the placeholder values, in order:
Send 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.
Routa checks the template and the parameters at accept time. If the template is not approved, the call fails right away with template_not_approved (or template_paused) instead of producing a message.failed later. A read-only template, or one being deleted, fails with template_not_sendable. A missing or extra parameter fails with content_rejected.