Bulk WhatsApp Messages
Send up to 100 WhatsApp messages to different recipients in a single API call.
Request Body
Send an array of message objects:
{
"messages": [
{
"from": "+919876500001",
"to": "+919876543210",
"content": {
"recipient_type": "individual",
"type": "text",
"text": { "body": "Hi Rahul, your order is ready!" }
}
},
{
"from": "+919876500001",
"to": "+919876543211",
"content": {
"recipient_type": "individual",
"type": "text",
"text": { "body": "Hi Priya, your order is ready!" }
}
}
]
}
Code Examples
- cURL
- Python
- Node.js
- PHP
- Go
curl -u '<api_key>:<api_token>' -X POST "https://api.exotel.com/v2/accounts/<sid>/messages" \
-H "Content-Type: application/json" \
-d '{
"messages": [
{
"from": "+919876500001",
"to": "+919876543210",
"content": {
"recipient_type": "individual",
"type": "template",
"template": {
"name": "order_ready",
"language": { "code": "en", "policy": "deterministic" },
"components": [{ "type": "body", "parameters": [{ "type": "text", "text": "Rahul" }] }]
}
}
},
{
"from": "+919876500001",
"to": "+919876543211",
"content": {
"recipient_type": "individual",
"type": "template",
"template": {
"name": "order_ready",
"language": { "code": "en", "policy": "deterministic" },
"components": [{ "type": "body", "parameters": [{ "type": "text", "text": "Priya" }] }]
}
}
}
]
}'
import requests
import json
payload = {
"messages": [
{
"from": "+919876500001",
"to": "+919876543210",
"content": {
"recipient_type": "individual",
"type": "template",
"template": {
"name": "order_ready",
"language": {"code": "en", "policy": "deterministic"},
"components": [{"type": "body", "parameters": [{"type": "text", "text": "Rahul"}]}],
},
},
},
{
"from": "+919876500001",
"to": "+919876543211",
"content": {
"recipient_type": "individual",
"type": "template",
"template": {
"name": "order_ready",
"language": {"code": "en", "policy": "deterministic"},
"components": [{"type": "body", "parameters": [{"type": "text", "text": "Priya"}]}],
},
},
},
]
}
response = requests.post(
'https://api.exotel.com/v2/accounts/<sid>/messages',
auth=('<api_key>', '<api_token>'),
headers={'Content-Type': 'application/json'},
data=json.dumps(payload)
)
print(response.json())
const apiKey = '<api_key>';
const apiToken = '<api_token>';
const accountSid = '<sid>';
const url = `https://api.exotel.com/v2/accounts/${accountSid}/messages`;
const payload = {
messages: [
{
from: '+919876500001',
to: '+919876543210',
content: {
recipient_type: 'individual',
type: 'template',
template: {
name: 'order_ready',
language: { code: 'en', policy: 'deterministic' },
components: [{ type: 'body', parameters: [{ type: 'text', text: 'Rahul' }] }],
},
},
},
{
from: '+919876500001',
to: '+919876543211',
content: {
recipient_type: 'individual',
type: 'template',
template: {
name: 'order_ready',
language: { code: 'en', policy: 'deterministic' },
components: [{ type: 'body', parameters: [{ type: 'text', text: 'Priya' }] }],
},
},
},
],
};
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Basic ' + Buffer.from(`${apiKey}:${apiToken}`).toString('base64'),
'Content-Type': 'application/json',
},
body: JSON.stringify(payload),
});
const data = await response.json();
console.log(data);
<?php
$payload = json_encode(array(
"messages" => array(
array(
"from" => "+919876500001",
"to" => "+919876543210",
"content" => array(
"recipient_type" => "individual",
"type" => "template",
"template" => array(
"name" => "order_ready",
"language" => array("code" => "en", "policy" => "deterministic"),
"components" => array(
array(
"type" => "body",
"parameters" => array(
array("type" => "text", "text" => "Rahul")
)
)
)
)
)
),
array(
"from" => "+919876500001",
"to" => "+919876543211",
"content" => array(
"recipient_type" => "individual",
"type" => "template",
"template" => array(
"name" => "order_ready",
"language" => array("code" => "en", "policy" => "deterministic"),
"components" => array(
array(
"type" => "body",
"parameters" => array(
array("type" => "text", "text" => "Priya")
)
)
)
)
)
)
)
));
$curl = curl_init();
curl_setopt_array($curl, array(
CURLOPT_USERPWD => "<api_key>:<api_token>",
CURLOPT_URL => "https://api.exotel.com/v2/accounts/<sid>/messages",
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POST => true,
CURLOPT_POSTFIELDS => $payload,
CURLOPT_HTTPHEADER => array("Content-Type: application/json"),
));
$response = curl_exec($curl);
curl_close($curl);
echo $response;
?>
package main
import (
"fmt"
"io/ioutil"
"net/http"
"strings"
)
func main() {
url := "https://api.exotel.com/v2/accounts/<sid>/messages"
payload := strings.NewReader(`{
"messages": [
{
"from": "+919876500001",
"to": "+919876543210",
"content": {
"recipient_type": "individual",
"type": "template",
"template": {
"name": "order_ready",
"language": { "code": "en", "policy": "deterministic" },
"components": [{ "type": "body", "parameters": [{ "type": "text", "text": "Rahul" }] }]
}
}
},
{
"from": "+919876500001",
"to": "+919876543211",
"content": {
"recipient_type": "individual",
"type": "template",
"template": {
"name": "order_ready",
"language": { "code": "en", "policy": "deterministic" },
"components": [{ "type": "body", "parameters": [{ "type": "text", "text": "Priya" }] }]
}
}
}
]
}`)
req, _ := http.NewRequest("POST", url, payload)
req.SetBasicAuth("<api_key>", "<api_token>")
req.Header.Add("Content-Type", "application/json")
res, _ := http.DefaultClient.Do(req)
defer res.Body.Close()
body, _ := ioutil.ReadAll(res.Body)
fmt.Println(string(body))
}
Response
{
"request_id": "a1b2c3d4",
"http_code": 202,
"metadata": {
"total": 2,
"success": 2,
"failed": 0
},
"response": {
"whatsapp": {
"messages": [
{ "code": 202, "status": "success", "data": { "sid": "msg_sid_1" } },
{ "code": 202, "status": "success", "data": { "sid": "msg_sid_2" } }
]
}
}
}
Limits
| Limit | Value |
|---|---|
| Max messages per request | 100 |
note
Each message in a bulk request is processed independently. The response includes per-message status so you can identify any individual failures.