Templates API
Create and manage message templates for your WhatsApp campaigns. Templates must be approved by WhatsApp before they can be used for sending messages.
List Templates
Get all message templates in your workspace.
GET /api/templates
Response:
[
{
"id": 1,
"name": "Welcome Message",
"content": "Hello {{firstName}}, welcome to {{companyName}}!",
"variables": ["firstName", "companyName"],
"status": "approved",
"language": "en",
"createdAt": "2025-01-01T00:00:00.000Z"
},
{
"id": 2,
"name": "Order Confirmation",
"content": "Hi {{firstName}}, your order #{{orderId}} has been confirmed.",
"variables": ["firstName", "orderId"],
"status": "approved",
"language": "en",
"createdAt": "2025-01-02T00:00:00.000Z"
}
]
cURL Example:
curl -X GET "https://waflow.edesy.in/api/templates" \
-H "Content-Type: application/json" \
-b cookies.txt
JavaScript Example:
const response = await fetch('https://waflow.edesy.in/api/templates', {
method: 'GET',
headers: {
'Content-Type': 'application/json',
},
credentials: 'include'
});
const templates = await response.json();
console.log(templates);
Create Template
Create a new message template.
POST /api/templates
Request Body:
{
"name": "Product Launch",
"content": "Hi {{firstName}}, check out our new {{productName}}! Available now at {{websiteUrl}}",
"variables": ["firstName", "productName", "websiteUrl"],
"language": "en"
}
Parameters:
| Field | Type | Required | Description |
|---|---|---|---|
| name | string | Yes | Template name (unique per workspace) |
| content | string | Yes | Message content with variables |
| variables | string[] | No | List of variable names used in content |
| language | string | Yes | Language code (e.g., "en", "es", "hi") |
Response:
{
"id": 2,
"name": "Product Launch",
"content": "Hi {{firstName}}, check out our new {{productName}}! Available now at {{websiteUrl}}",
"variables": ["firstName", "productName", "websiteUrl"],
"status": "draft",
"language": "en",
"createdAt": "2025-01-01T00:00:00.000Z"
}
cURL Example:
curl -X POST "https://waflow.edesy.in/api/templates" \
-H "Content-Type: application/json" \
-b cookies.txt \
-d '{
"name": "Product Launch",
"content": "Hi {{firstName}}, check out our new {{productName}}! Available now at {{websiteUrl}}",
"variables": ["firstName", "productName", "websiteUrl"],
"language": "en"
}'
Template Variables
Variables allow you to personalize messages for each recipient. Use double curly braces to define variables:
Hello {{firstName}}, your order {{orderId}} is ready!
Standard Variables
These variables are automatically populated from contact data:
| Variable | Source |
|---|---|
{{firstName}} |
Contact's first name |
{{lastName}} |
Contact's last name |
{{phoneNumber}} |
Contact's phone number |
{{email}} |
Contact's email address |
Custom Variables
You can define custom variables that are populated at send time:
| Variable | Example |
|---|---|
{{orderId}} |
Dynamic order ID |
{{appointmentDate}} |
Scheduled appointment |
{{discountCode}} |
Promotional code |
{{trackingUrl}} |
Delivery tracking link |
Template Status
Templates go through an approval process:
| Status | Description |
|---|---|
draft |
Template created, not yet submitted |
pending |
Submitted to WhatsApp for approval |
approved |
Approved and ready to use |
rejected |
Rejected by WhatsApp |
Note: Only
approvedtemplates can be used in campaigns.
WhatsApp Template Categories
WhatsApp categorizes templates based on their purpose:
| Category | Use Case | Example |
|---|---|---|
| MARKETING | Promotions, offers | "50% off sale this weekend!" |
| UTILITY | Transactional updates | "Your order has shipped" |
| AUTHENTICATION | OTPs, verification | "Your verification code is 123456" |
Tip: UTILITY templates generally have higher approval rates than MARKETING templates.
Best Practices
- Clear purpose - Each template should have a single, clear purpose
- Professional tone - Avoid aggressive marketing language
- Include opt-out - For marketing messages, include an opt-out option
- Test thoroughly - Preview templates with sample data before submitting
- Follow guidelines - Review WhatsApp's template guidelines
Error Responses
Duplicate Name (400):
{
"success": false,
"error": {
"code": "DUPLICATE_NAME",
"message": "A template with this name already exists"
}
}
Invalid Variables (400):
{
"success": false,
"error": {
"code": "INVALID_VARIABLES",
"message": "Variable names must be alphanumeric"
}
}