Documentation menu

Templates

Reusable message bodies with {{variables}}, so your copy stays consistent.

Create a template

curl
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.

201 Created
{
  "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
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

MethodPathPurpose
GET/v1/templatesList your templates
POST/v1/templatesCreate a template
PATCH/v1/templates/:idUpdate name or body
DELETE/v1/templates/:idDelete a template