Templates
Create and manage reusable SMS message templates with dynamic variables
Templates
Templates let you define reusable SMS message bodies with dynamic {{variable}} placeholders. Reference a template when composing SMS to keep content consistent and reduce repetition.
Create a template
POST /templates
Request body
{
"name": "OTP Verification",
"content": "Your {{appName}} verification code is {{code}}. Valid for {{minutes}} minutes."
}| Field | Type | Required | Description |
|---|---|---|---|
name | string | Yes | Human-readable name for the template |
content | string | Yes | Message body. Use {{variableName}} for dynamic values |
subject | string | No | Optional subject (for future email support) |
Response 201
Returns the new template ID (UUID).
Code sample
curl -X POST https://api.castbrick.co/v1/templates \
-H "Authorization: Bearer cb_live_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"name": "OTP Verification",
"content": "Your {{appName}} verification code is {{code}}. Valid for {{minutes}} minutes."
}'List templates
GET /templates
Query parameters
| Parameter | Default | Description |
|---|---|---|
pageNumber | 1 | Page number |
pageSize | 20 | Results per page |
Response 200
{
"items": [
{
"id": "3fa85f64-5717-4562-b3fc-2c963f66afa6",
"name": "OTP Verification",
"content": "Your {{appName}} verification code is {{code}}. Valid for {{minutes}} minutes.",
"createdAt": "2026-01-15T10:00:00Z"
}
],
"totalCount": 5,
"pageNumber": 1,
"totalPages": 1,
"hasNextPage": false,
"hasPreviousPage": false
}Code sample
curl "https://api.castbrick.co/v1/templates?pageNumber=1&pageSize=20" \
-H "Authorization: Bearer cb_live_xxxxxxxxxxxx"Update a template
PUT /templates/{id}
Request body
{
"name": "OTP Verification v2",
"content": "{{appName}}: your code is {{code}}. Expires in {{minutes}} min. Do not share."
}Code sample
curl -X PUT https://api.castbrick.co/v1/templates/3fa85f64-5717-4562-b3fc-2c963f66afa6 \
-H "Authorization: Bearer cb_live_xxxxxxxxxxxx" \
-H "Content-Type: application/json" \
-d '{
"name": "OTP Verification v2",
"content": "{{appName}}: your code is {{code}}. Expires in {{minutes}} min."
}'Delete a template
DELETE /templates/{id}
Permanently removes the template. Returns 204 No Content.
curl -X DELETE https://api.castbrick.co/v1/templates/3fa85f64-5717-4562-b3fc-2c963f66afa6 \
-H "Authorization: Bearer cb_live_xxxxxxxxxxxx"Using templates when sending SMS
Resolve the template on your side before calling /sms/send — substitute the {{variable}} placeholders with the actual values:
import { CastBrick } from 'castbrick-js';
const cb = new CastBrick({ apiKey: process.env.CASTBRICK_API_KEY! });
// 1. Fetch the template
const { items } = await cb.contacts.listLists(); // illustrative — fetch your template via HTTP
// 2. Render it
const template = "Your {{appName}} code is {{code}}. Valid for {{minutes}} minutes.";
const content = template
.replace('{{appName}}', 'MyApp')
.replace('{{code}}', '482917')
.replace('{{minutes}}', '10');
// 3. Send
await cb.sms.send({
recipients: ['+244923000000'],
content,
});import re
template = "Your {{appName}} code is {{code}}. Valid for {{minutes}} minutes."
variables = {"appName": "MyApp", "code": "482917", "minutes": "10"}
content = re.sub(r'\{\{(\w+)\}\}', lambda m: variables.get(m.group(1), m.group(0)), template)
cb.sms.send(to=["+244923000000"], content=content)Variable naming conventions
- Use camelCase:
{{firstName}},{{orderNumber}},{{expiryDate}} - Variables are case-sensitive:
{{Code}}≠{{code}} - Undefined variables are left as-is in the rendered content — always validate before sending