Templates
Reusable message bodies with {{variables}}, so your copy stays consistent.
Create a template
curl https://api.sms.pesarails.com/v1/templates \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"name": "otp",
"body": "Your {{brand}} code is {{code}}. It expires in 5 minutes."
}'Variables are detected automatically from the body. The response lists them back to you.
{
"template": {
"id": "tpl_7h2k",
"name": "otp",
"body": "Your {{brand}} code is {{code}}. It expires in 5 minutes.",
"variables": ["brand", "code"]
}
}Send from a template
Pass templateId and variables instead of message.
curl https://api.sms.pesarails.com/v1/messages \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"to": "254712345678",
"sender": "PESARAILS",
"templateId": "tpl_7h2k",
"variables": { "brand": "Acme", "code": "4821" }
}'The rendered message is Your Acme code is 4821. It expires in 5 minutes.
Note
An unknown variable renders as an empty string, so always pass every variable the template declares.
Manage templates
| Method | Path | Purpose |
|---|---|---|
| GET | /v1/templates | List your templates |
| POST | /v1/templates | Create a template |
| PATCH | /v1/templates/:id | Update name or body |
| DELETE | /v1/templates/:id | Delete a template |