Keeping transactional SMS wording in templates through the API: create, change and reuse

WhatsApp & APIs·· 9 views· 3 min read

The short answer: notice texts do not have to be written into your code. Through the API, POST /v1/sms/templates saves a text as a template, PATCH /v1/sms/templates/{id} changes it and GET /v1/sms/templates/{id} reads it. They are the same templates as on the SMS page in Meu Interweb: whoever looks after your communication changes the wording there, and your system starts sending the new wording without anyone touching the code.

The operations

Operation What it does Permission
GET /v1/sms/templates Lists the account's templates. sms:read
GET /v1/sms/templates/{id} Shows one template. sms:read
POST /v1/sms/templates Creates a template. sms:write
PATCH /v1/sms/templates/{id} Changes a template. sms:write
DELETE /v1/sms/templates/{id} Deletes a template. sms:write
A template sends nothing. It only keeps the text. Sending is still POST /v1/sms/messages, with the finished text in the text field.

The variables a template accepts

Through the API, a template text accepts the sender-side variables: {$client_name}, {$client_first_name}, {$client_last_name}, {$client_company_name}, {$remetente} and {$data}. Any other variable makes the API answer 422. The event data (order number, amount, time) are not API variables: your system puts them into the text.

A simple way to work

1 Create one template per event (payment received, order shipped, booking confirmed) and keep each template's id in your system's settings.
2 Mark the places for event data with something your system recognises and replaces, such as [ORDER NO].
3 When the event happens, the system reads the template (or uses a recent copy), swaps the marks for the data and sends with POST /v1/sms/messages.
4 Before sending, it checks that no mark is left. If one is, it does not send and alerts someone: a text showing [ORDER NO] looks careless.

These templates count towards the same account limit as the ones on the SMS page, up to 100. A deleted template does not come back, so your system should know what to do if the id disappears: use a fallback text and alert the team.

Reading the template for every SMS uses up requests. Keep a copy for a few minutes and read it again after that. A change made in Meu Interweb still reaches your system quickly, without eating into the request limit.

Want wording your team can change without touching the code? See Transactional SMS.

See Transactional SMS

SEE ALSO

SMS templates and AI: ready-made messages, the template library and improving a text

Personalised SMS with the contact's name: variables, examples and pitfalls

Writing transactional SMS: the key fact first, references and amounts, and one part only

Sending SMS through the API: key, permissions, Sandbox and your first request

A reusable send-SMS function in PHP, Python or Node.js, with timeouts and error handling

Sent a transactional SMS with a mistake: what you can undo and how to send the correction

RECOMMENDED PRODUCT

Web hosting with cPanel

Domain and SSL included, daily backups and the panel you already know. from $5.36/mo (3-year plan, with coupon)

See plans
Was this answer helpful? Your answer helps us improve this article.