Templates let you create reusable message content with dynamic variables. They’re essential for WhatsApp Business API and recommended for consistent messaging across all channels.
Why Use Templates?
- Consistency: Ensure uniform messaging across your team
- WhatsApp compliance: Required for messages outside the 24-hour window
- Efficiency: Avoid rewriting common messages
- Analytics: Track performance by template
Creating a Template
Basic Template
curl -X POST https://api.zavu.dev/v1/templates \
-H "Authorization: Bearer zv_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"name": "order_confirmation",
"category": "transactional",
"body": "Hi {{customerName}}, your order #{{orderId}} has been confirmed! Estimated delivery: {{deliveryDate}}."
}'
Variable Syntax
Use double curly braces for variables:
Hi {{customerName}}, your order #{{orderId}} has been confirmed!
Variables are automatically extracted from the template body.
Template Categories
| Category | Use Case | Example |
|---|
transactional | Order updates, receipts, confirmations | ”Your order has shipped” |
marketing | Promotions, offers, newsletters | ”50% off this weekend!” |
alert | Security, account, system alerts | ”New login detected” |
Using Templates
Send with Template
curl -X POST https://api.zavu.dev/v1/messages \
-H "Authorization: Bearer zv_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"to": "+56912345678",
"templateId": "tpl_abc123",
"data": {
"customerName": "John",
"orderId": "12345",
"deliveryDate": "January 20, 2024"
}
}'
SDK Examples
const message = await zavu.messages.send({
to: '+56912345678',
templateId: 'tpl_abc123',
data: {
customerName: 'John',
orderId: '12345',
deliveryDate: 'January 20, 2024'
}
});
Variable Handling
Missing Variables
If a variable is missing from the data object, it’s replaced with an empty string:
Template: "Hi {{name}}, your code is {{code}}"
Data: { "code": "123456" }
Result: "Hi , your code is 123456"
Always provide all required variables to avoid awkward messages.
Variable Types
Variables can be strings, numbers, or booleans:
{
"data": {
"name": "John", // string
"orderTotal": 99.99, // number
"isPremium": true // boolean (rendered as "true")
}
}
Null Values
Null values are rendered as empty strings:
{
"data": {
"middleName": null // Rendered as ""
}
}
Managing Templates
List Templates
curl https://api.zavu.dev/v1/templates \
-H "Authorization: Bearer zv_live_xxx"
Get Template
curl https://api.zavu.dev/v1/templates/tpl_abc123 \
-H "Authorization: Bearer zv_live_xxx"
Update Template
curl -X PATCH https://api.zavu.dev/v1/templates/tpl_abc123 \
-H "Authorization: Bearer zv_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"body": "Hi {{customerName}}! Order #{{orderId}} confirmed. Arriving {{deliveryDate}}."
}'
Delete Template
curl -X DELETE https://api.zavu.dev/v1/templates/tpl_abc123 \
-H "Authorization: Bearer zv_live_xxx"
WhatsApp Templates
WhatsApp requires pre-approved templates for messages outside the 24-hour conversation window.
Creating WhatsApp Templates
Include WhatsApp-specific configuration:
curl -X POST https://api.zavu.dev/v1/templates \
-H "Authorization: Bearer zv_live_xxx" \
-H "Content-Type: application/json" \
-d '{
"name": "shipping_update",
"category": "transactional",
"body": "Hi {{name}}, your package is on the way! Track: {{trackingUrl}}",
"channels": ["whatsapp"],
"whatsapp": {
"templateName": "shipping_update_v1",
"namespace": "your_waba_namespace"
}
}'
Approval Status
Check template approval status:
{
"id": "tpl_abc123",
"name": "shipping_update",
"whatsapp": {
"templateName": "shipping_update_v1",
"namespace": "your_waba_namespace",
"status": "approved" // pending, approved, rejected
}
}
| Status | Meaning |
|---|
pending | Submitted, awaiting Meta review |
approved | Ready to use |
rejected | Not approved - check rejection reason |
Best Practices
Naming Conventions
Use descriptive, consistent names:
order_confirmation
shipping_update
password_reset
appointment_reminder
promotional_offer
Version Control
Include version in WhatsApp template names for updates:
order_confirmation_v1
order_confirmation_v2
Testing
Test templates before production use:
# Send to a test number
curl -X POST https://api.zavu.dev/v1/messages \
-H "Authorization: Bearer zv_test_xxx" \
-H "Content-Type: application/json" \
-d '{
"to": "+your_phone_number",
"templateId": "tpl_abc123",
"data": {
"customerName": "Test User",
"orderId": "TEST-001"
}
}'
Character Limits
Keep templates concise:
| Channel | Recommendation |
|---|
| SMS | Under 160 characters |
| WhatsApp | Under 1024 characters |