Template Message
Send personalized WhatsApp messages using pre-approved templates
Templates enable personalized communication while ensuring compliance with WhatsApp's business policies. This API lets you send template-based messages to your customers with dynamic content.
WhatsApp requires businesses to use pre-approved templates for initiating conversations. This API allows you to send template messages with personalized variables, media attachments, and interactive components to your customers.
Overview
The Send Template Message API enables you to:
- Send WhatsApp messages using your pre-approved templates
- Dynamically replace variables with personalized content
- Attach media (images, videos, documents) when supported by the template
- Include interactive elements like buttons and quick replies
- Track delivery status through WhatsApp response information
Legacy API reference
The field reference for this legacy endpoint.
Send Template Message
Send a personalized WhatsApp template message to a specific phone number.
Endpoint
POST https://api.insightssystem.com/api:hFrjh8a1/send_template_message_by_apiAuthentication
All API requests require authentication using your API key. Never share your API keys in client-side code.
Include your API key in all requests using Bearer authentication:
Authorization: Bearer YOUR_API_KEYRequest Body
The unique identifier of the template to use. You can retrieve this from the Get Templates API.
The recipient's phone number in international format with country code (e.g., "+123476529999").
Object containing key-value pairs for template variables. The keys must match the variable names defined in your template.
Show Variable Types
Text variables that replace placeholders in the message body (e.g., body1, body2, etc.)
Text variables that replace placeholders in the message header
Public URL to media content (image, video, or document) for templates with media support
Set to "1" to enable dynamic button links in interactive templates
Response
The API returns a detailed response indicating whether the message was accepted for delivery and provides WhatsApp message identifiers for tracking.
Indicates if the request was successfully processed
Details from the WhatsApp Business API about the message delivery
Show WhatsApp Response Fields
Always "whatsapp" for WhatsApp messages
Information about the message recipient
The phone number that was provided in the request
WhatsApp's unique identifier for the recipient
Details about the sent message
Unique message identifier (wamid) for tracking status
Initial status of the message (typically "accepted")
Present only when an error occurs
Error code identifier
Human-readable error description
Example Request
curl -X POST \
'https://api.insightssystem.com/api:hFrjh8a1/send_template_message_by_api' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer YOUR_API_KEY' \
-d '{
"template": "f10695a9-38d6-4f5f-8444-1f7bf52c6164",
"phone_number": "+123476529999",
"variables": {
"body1": "Axel",
"body2": "Shampoo",
"body3": "$1",
"media": "https://drive.google.com/file/d/1D35uTbceRPmCgwxVfBJZ2yxD2lQgs0bi/view?usp=sharing",
"visit_website": "1"
}
}'Example Response
{
"success": true,
"whatsapp_response_info": {
"messaging_product": "whatsapp",
"contacts": [
{
"input": "+123476529999",
"wa_id": "123476529999"
}
],
"messages": [
{
"id": "wamid.HBgLMTIzNDc2NTI5OTk5FQIAERgSNUU2RjM4NzM1M0Q5OEIwQTQwAA==",
"message_status": "accepted"
}
]
}
}Response Codes
Your request was successful and the message has been accepted for delivery.
The request was invalid. Check the error message for details.
{
"success": false,
"error": {
"code": "invalid_request",
"message": "Missing required field: template"
}
}Authentication failed. Check that you're using a valid API key.
{
"success": false,
"error": {
"code": "unauthorized",
"message": "Invalid API key provided"
}
}Your account doesn't have permission to send messages.
The template specified doesn't exist.
{
"success": false,
"error": {
"code": "template_not_found",
"message": "Template with ID 'f10695a9-38d6-4f5f-8444-1f7bf52c6164' not found"
}
}The request was well-formed but contains invalid parameters.
{
"success": false,
"error": {
"code": "invalid_phone_number",
"message": "The phone number format is invalid"
}
}You've exceeded the rate limit. Implement exponential backoff in your requests.
Something went wrong on our end. Please contact support if the issue persists.
{
"success": false,
"error": {
"code": "server_error",
"message": "An internal server error occurred"
}
}Working with Template Variables
Templates contain placeholders that are replaced with dynamic content when sending messages. Understanding how to map your data to these variables is essential.
Variable Types
Text Variables
Body and header variables replace text placeholders in your template. They are named body1, body2, etc., or header1, header2, etc.
Media Variables
Media variables allow you to attach images, videos, or documents to your template. Provide a public URL in the media property.
Button Variables
Used for dynamic buttons in interactive templates. Use visit_website set to "1" to enable dynamic button URLs.
Quick Reply Variables
For templates with quick reply buttons, provide the text to display on each button.
Variable Mapping
Identify template variables
Examine your template structure to identify which variables are required. You can find this information using the Get Templates API.
Prepare your data
Format your data to match the expected variable structure. Ensure values meet any length or format requirements.
Map data to variables
Create a variables object with keys matching your template's variable names and values from your data.
Handle media properly
For media templates, ensure your media URL is publicly accessible and in a WhatsApp-supported format.
Media Guidelines
When including media in your templates, follow these guidelines for optimal delivery:
Images
- Supported formats: JPG, JPEG, PNG
- Max size: 5MB
- Recommended aspect ratio: 1.91:1
Videos
- Supported formats: MP4, 3GPP
- Max size: 16MB
- Max duration: 1 minute
Documents
- Supported formats: PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX
- Max size: 100MB
URLs
- Must be publicly accessible
- Direct file links (no redirects)
- HTTPS required
Media URLs must be publicly accessible without requiring authentication. For security, we recommend using signed URLs with limited-time access.
Best Practices
Error Handling
Implement comprehensive error handling to manage API failures gracefully. Always check the success field in responses and handle various error scenarios.
Message Tracking
This endpoint offers no way to track delivery. To track a message, send it through Send a message (API v1), then look up its id with Read a message (API v1).
Throttling
Implement request throttling when sending to multiple recipients to avoid hitting rate limits and ensure reliable delivery.
Template Testing
Test your templates with various inputs to ensure variables are correctly replaced and messages appear as expected.
FAQs
Messages may fail to deliver for several reasons: invalid phone number, recipient has blocked your WhatsApp Business number, template issues, or WhatsApp temporary service interruptions. Check the error code returned for specific details.
No, recipients must have an active WhatsApp account associated with the phone number you're sending to.
The initial response only confirms that WhatsApp accepted the message. This endpoint offers no delivery status, and outgoing webhooks send only received and sent messages. To track delivery, send through Send a message (API v1), then look up the message id it returns with Read a message (API v1).
No, WhatsApp messages cannot be edited once sent. You would need to send a new message with the corrected information.
Need help?
Our support team can assist with template issues, API integration, or any other questions.