Templates API
The Template API allows businesses to send pre-approved WhatsApp template messages to customers, either with or without media attachments. All templates must receive WhatsApp approval before they can be used for message delivery.
Send Template Message (No Media Attachment)
This endpoint enables you to send WhatsApp template messages without any media content, such as images, documents, videos, or locations.
Endpoint :
https://BASE_URL/api/send/template
Request Type : POST
Options | Required | Description |
---|---|---|
phone_number | yes | string The destination phone number. Phone number must be in the international format ( Example: 23490126727 ). |
device_id | yes | string Represents the Device ID for Whatsapp. It can be Alphanumeric. It should be passed when the message is sent via whatsapp (It can be found on the manage device page on your Termii dashboard) |
template_id | yes | string The ID of the template used |
api_key | yes | string Your API key (It can be found on your Termii dashboard). |
data | yes | object Represents the variables used in your WhatsApp template. These key-value pairs will dynamically populate the placeholders in your approved template message. You can find the required keys for each template on the Device Subscription page of your dashboard. ( Example: {"studname": "Victor", "average": "30" } ) |
{
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"product_name": "Termii",
"otp" : 120435,
"expiry_time": "10 minutes"
}
}
var data = {
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"product_name": "Termii",
"otp" : 120435,
"expiry_time": "10 minutes"
}
};
var data = JSON.stringify(data);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", " https://BASE_URL/api/send/template");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
var request = require('request');
var data = {
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"product_name": "Termii",
"otp" : 120435,
"expiry_time": "10 minutes"
}
};
var options = {
'method': 'POST',
'url': ' https://BASE_URL/api/send/template',
'headers': {
'Content-Type': ['application/json', 'application/json']
},
body: JSON.stringify(data)
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
url = "https://BASE_URL/api/send/template"
payload = {
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"product_name": "Termii",
"otp" : 120435,
"expiry_time": "10 minutes"
}
}
headers = {
'Content-Type': 'application/json',
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)
var client = new RestClient("https://BASE_URL/api/send/template");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", " {\r\n \"phone_number\": \"2347880234567\",\r\n \"device_id\": \"f3f4f7b0-52d8-40bc-91fc-120da11ff936\",\r\n \"template_id\": \"1493-csdn3-ns34w-sd3434-dfdf\",\r\n \"api_key\": \"plain\",\r\n \"data\": {\r\n \"product_name\": \"Termii\",\r\n \"otp\" : 120435,\r\n \"expiry_time\": \"10 minutes\"\r\n } \r\n }",
ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.POST(" https://BASE_URL/api/send/template")
.header("Content-Type", "application/json")
.body(" {\r\n \"phone_number\": \"2347880234567\",\r\n \"device_id\": \"f3f4f7b0-52d8-40bc-91fc-120da11ff936\",\r\n \"template_id\": \"1493-csdn3-ns34w-sd3434-dfdf\",\r\n \"api_key\": \"plain\",\r\n \"data\": {\r\n \"product_name\": \"Termii\",\r\n \"otp\" : 120435,\r\n \"expiry_time\": \"10 minutes\"\r\n } \r\n }")
.asString();
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://BASE_URL/api/send/template',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_POSTFIELDS =>' {
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"product_name": "Termii",
"otp" : 120435,
"expiry_time": "10 minutes"
}
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Sample Response - 200 OK
{
"code": "ok",
"balance": 5013.4,
"message_id": "3017516375426287994947985",
"message": "Successfully Sent",
"user": "Termii Inc",
"message_id_str": "3017516375426287994947985"
}
Send Template Message with Media Attachment
This endpoint allows you to send WhatsApp template messages that include media content, such as images, documents, videos, or locations.
Endpoint :
https://BASE_URL/api/send/template/media
Request Type : POST
Options | Required | Description |
---|---|---|
phone_number | yes | string The destination phone number. Phone number must be in the international format ( Example: 23490126727 ). |
device_id | yes | string Represents the Device ID for Whatsapp. It can be Alphanumeric. It should be passed when the message is sent via whatsapp (It can be found on the manage device page on your Termii dashboard) |
template_id | yes | string The ID of the template used |
api_key | yes | string Your API key (It can be found on your Termii dashboard). |
data | yes | object Represents the variables used in your WhatsApp template. These key-value pairs will dynamically populate the placeholders in your approved template message. You can find the required keys for each template on the Device Subscription page of your dashboard. ( Example: {"name": "Termii" } ) |
media | yes | object This specifies the media details included in the message. |
media.caption | yes | string Provides a caption describing the attached media, such as Image, Document, Location, or Video.. |
media.url | yes | string The publicly accessible URL of the media file (image, document, video, or location). The link must point directly to the file and be downloadable. If the link is not downloadable, the message will not be delivered. Examples: https://docs.google.com/document/d/.../export?format=pdf |
{
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"name": "Windows"
},
"media":{
"caption":"Document",
"url":"https://docs.google.com/document/d/....."
}
}
var data = {
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"name": "Windows"
},
"media":{
"caption":"Document",
"url":"https://docs.google.com/document/d/....."
}
};
var data = JSON.stringify(data);
var xhr = new XMLHttpRequest();
xhr.withCredentials = true;
xhr.addEventListener("readystatechange", function() {
if(this.readyState === 4) {
console.log(this.responseText);
}
});
xhr.open("POST", " https://BASE_URL/api/send/template");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.setRequestHeader("Content-Type", "application/json");
xhr.send(data);
var request = require('request');
var data = {
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"name": "Windows"
},
"media":{
"caption":"Document",
"url":"https://docs.google.com/document/d/....."
}
};
var options = {
'method': 'POST',
'url': ' https://BASE_URL/api/send/template',
'headers': {
'Content-Type': ['application/json', 'application/json']
},
body: JSON.stringify(data)
};
request(options, function (error, response) {
if (error) throw new Error(error);
console.log(response.body);
});
import requests
url = "https://BASE_URL/api/send/template"
payload = {
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"name": "Windows"
},
"media":{
"caption":"Document",
"url":"https://docs.google.com/document/d/....."
}
}
headers = {
'Content-Type': 'application/json',
}
response = requests.request("POST", url, headers=headers, json=payload)
print(response.text)
var client = new RestClient("https://BASE_URL/api/send/template");
client.Timeout = -1;
var request = new RestRequest(Method.GET);
request.AddHeader("Content-Type", "application/json");
request.AddParameter("application/json", " {\r\n \"phone_number\": \"2347880234567\",\r\n \"device_id\": \"f3f4f7b0-52d8-40bc-91fc-120da11ff936\",\r\n \"template_id\": \"1493-csdn3-ns34w-sd3434-dfdf\",\r\n \"api_key\": \"plain\",\r\n \"data\": {\r\n \"product_name\": \"Termii\",\r\n \"otp\" : 120435,\r\n \"expiry_time\": \"10 minutes\"\r\n } \r\n }",
ParameterType.RequestBody);
IRestResponse response = client.Execute(request);
Console.WriteLine(response.Content);
Unirest.setTimeouts(0, 0);
HttpResponse<String> response = Unirest.POST(" https://BASE_URL/api/send/template")
.header("Content-Type", "application/json")
.body(" {\r\n \"phone_number\": \"2347880234567\",\r\n \"device_id\": \"f3f4f7b0-52d8-40bc-91fc-120da11ff936\",\r\n \"template_id\": \"1493-csdn3-ns34w-sd3434-dfdf\",\r\n \"api_key\": \"plain\",\r\n \"data\": {\r\n \"product_name\": \"Termii\",\r\n \"otp\" : 120435,\r\n \"expiry_time\": \"10 minutes\"\r\n } \r\n }")
.asString();
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_URL => 'https://BASE_URL/api/send/template',
CURLOPT_RETURNTRANSFER => true,
CURLOPT_ENCODING => '',
CURLOPT_MAXREDIRS => 10,
CURLOPT_TIMEOUT => 0,
CURLOPT_FOLLOWLOCATION => true,
CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
CURLOPT_CUSTOMREQUEST => 'GET',
CURLOPT_POSTFIELDS =>' {
"phone_number": "2347880234567",
"device_id": "f3f4f7b0-52d8-40bc-91fc-120da11ff936",
"template_id": "1493-csdn3-ns34w-sd3434-dfdf",
"api_key": "plain",
"data": {
"name": "Windows"
},
"media":{
"caption":"Document",
"url":"https://docs.google.com/document/d/....."
}
}',
CURLOPT_HTTPHEADER => array(
'Content-Type: application/json'
),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
Sample Response - 200 OK
{
"code": "ok",
"balance": 5013.4,
"message_id": "3017516375426287994947985",
"message": "Successfully Sent",
"user": "Termii Inc",
"message_id_str": "3017516375426287994947985"
}