Broadcasts
Send WhatsApp template messages to many recipients with per-recipient variables and scheduling
Quick Start
Send a WhatsApp template message to multiple recipients. Create a broadcast, add phone numbers, and send:
import Zernio from '@zernio/node';
const zernio = new Zernio();
// Step 1: Create a WhatsApp broadcast with a Meta-approved template
const { data: broadcast } = await zernio.broadcasts.createBroadcast({
body: {
profileId: 'YOUR_PROFILE_ID',
accountId: 'YOUR_WHATSAPP_ACCOUNT_ID',
platform: 'whatsapp',
name: 'Welcome Campaign',
template: {
name: 'hello_world',
language: 'en'
}
}
});
// Step 2: Add WhatsApp recipients by phone number
await zernio.broadcasts.addBroadcastRecipients({
path: { broadcastId: broadcast.broadcast.id },
body: {
phones: ['+1234567890', '+0987654321']
}
});
// Step 3: Send the WhatsApp broadcast
const { data: result } = await zernio.broadcasts.sendBroadcast({
path: { broadcastId: broadcast.broadcast.id }
});
console.log(`Sent: ${result.sent}, Failed: ${result.failed}`);from zernio import Zernio
client = Zernio()
# Step 1: Create a WhatsApp broadcast with a Meta-approved template
broadcast = client.broadcasts.create_broadcast(
profile_id='YOUR_PROFILE_ID',
account_id='YOUR_WHATSAPP_ACCOUNT_ID',
platform='whatsapp',
name='Welcome Campaign',
template={
'name': 'hello_world',
'language': 'en'
}
)
# Step 2: Add WhatsApp recipients by phone number
client.broadcasts.add_broadcast_recipients(
broadcast_id=broadcast.broadcast.id,
phones=['+1234567890', '+0987654321']
)
# Step 3: Send the WhatsApp broadcast
result = client.broadcasts.send_broadcast(
broadcast_id=broadcast.broadcast.id
)
print(f"Sent: {result.sent}, Failed: {result.failed}")# Step 1: Create a WhatsApp broadcast
BROADCAST_ID=$(curl -s -X POST https://zernio.com/api/v1/broadcasts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"profileId": "YOUR_PROFILE_ID",
"accountId": "YOUR_WHATSAPP_ACCOUNT_ID",
"platform": "whatsapp",
"name": "Welcome Campaign",
"template": {
"name": "hello_world",
"language": "en"
}
}' | jq -r '.broadcast.id')
# Step 2: Add WhatsApp recipients by phone number
curl -X POST "https://zernio.com/api/v1/broadcasts/$BROADCAST_ID/recipients" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"phones": ["+1234567890", "+0987654321"]}'
# Step 3: Send the WhatsApp broadcast
curl -X POST "https://zernio.com/api/v1/broadcasts/$BROADCAST_ID/send" \
-H "Authorization: Bearer YOUR_API_KEY"Broadcasts
Send WhatsApp template messages to many recipients at once. Broadcasts support per-recipient template variables, scheduling, and delivery tracking (sent, delivered, read).
Create a Broadcast
Create a WhatsApp broadcast by specifying your WABA account and a Meta-approved template:
const { data } = await zernio.broadcasts.createBroadcast({
body: {
profileId: 'YOUR_PROFILE_ID',
accountId: 'YOUR_WHATSAPP_ACCOUNT_ID',
platform: 'whatsapp',
name: 'January Newsletter',
template: {
name: 'monthly_update',
language: 'en',
components: [{
type: 'body',
parameters: [{ type: 'text', text: '{{1}}' }]
}]
}
}
});
console.log('Broadcast created:', data.broadcast.id);response = client.broadcasts.create_broadcast(
profile_id='YOUR_PROFILE_ID',
account_id='YOUR_WHATSAPP_ACCOUNT_ID',
platform='whatsapp',
name='January Newsletter',
template={
'name': 'monthly_update',
'language': 'en',
'components': [{
'type': 'body',
'parameters': [{'type': 'text', 'text': '{{1}}'}]
}]
}
)
print(f"Broadcast created: {response.broadcast.id}")curl -X POST https://zernio.com/api/v1/broadcasts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"profileId": "YOUR_PROFILE_ID",
"accountId": "YOUR_WHATSAPP_ACCOUNT_ID",
"platform": "whatsapp",
"name": "January Newsletter",
"template": {
"name": "monthly_update",
"language": "en",
"components": [{
"type": "body",
"parameters": [{"type": "text", "text": "{{1}}"}]
}]
}
}'Template Variables
WhatsApp templates use numbered placeholders ({{1}}, {{2}}, and so on) defined in the template body when you create it, for example Hi {{1}}, your order {{2}} has been confirmed!. Only numbered placeholders are supported, not named ones.
To fill those placeholders, add a variableMapping to the broadcast's template. It maps each placeholder position to a contact field or a static value, and Zernio resolves it for every recipient automatically at send time (so {{1}} becomes each contact's own name, {{2}} their order number, and so on):
const { data } = await zernio.broadcasts.createBroadcast({
body: {
profileId: 'YOUR_PROFILE_ID',
accountId: 'YOUR_WHATSAPP_ACCOUNT_ID',
platform: 'whatsapp',
name: 'Order Confirmations',
template: {
name: 'order_confirmation',
language: 'en',
components: [{
type: 'body',
parameters: [
{ type: 'text', text: '{{1}}' },
{ type: 'text', text: '{{2}}' }
]
}],
// Resolved per recipient at send time
variableMapping: {
'1': { field: 'name' }, // each contact's name
'2': { field: 'custom', customValue: 'VIP-2025' } // same value for everyone
}
}
}
});response = client.broadcasts.create_broadcast(
profile_id='YOUR_PROFILE_ID',
account_id='YOUR_WHATSAPP_ACCOUNT_ID',
platform='whatsapp',
name='Order Confirmations',
template={
'name': 'order_confirmation',
'language': 'en',
'components': [{
'type': 'body',
'parameters': [
{'type': 'text', 'text': '{{1}}'},
{'type': 'text', 'text': '{{2}}'}
]
}],
# Resolved per recipient at send time
'variableMapping': {
'1': {'field': 'name'}, # each contact's name
'2': {'field': 'custom', 'customValue': 'VIP-2025'} # same value for everyone
}
}
)curl -X POST https://zernio.com/api/v1/broadcasts \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{
"profileId": "YOUR_PROFILE_ID",
"accountId": "YOUR_WHATSAPP_ACCOUNT_ID",
"platform": "whatsapp",
"name": "Order Confirmations",
"template": {
"name": "order_confirmation",
"language": "en",
"components": [{
"type": "body",
"parameters": [
{"type": "text", "text": "{{1}}"},
{"type": "text", "text": "{{2}}"}
]
}],
"variableMapping": {
"1": { "field": "name" },
"2": { "field": "custom", "customValue": "VIP-2025" }
}
}
}'Each variableMapping entry maps a position to one of these field values:
field | Resolves to |
|---|---|
name | The contact's name (falls back to "there" if unset) |
phone | The recipient's phone number |
email | The contact's email |
company | The contact's company |
custom | The literal customValue string (same for every recipient) |
The number of variableMapping entries must match the number of placeholders in the template body. A mismatch makes Meta reject the send with a parameter-count error (code 132000).
Add Recipients
Add WhatsApp recipients by phone number, existing contact IDs, or by matching your contact segment filters. Phone numbers are in E.164 format (e.g., +1234567890):
// Add WhatsApp recipients by phone number (auto-creates contacts)
const { data } = await zernio.broadcasts.addBroadcastRecipients({
path: { broadcastId: 'BROADCAST_ID' },
body: {
phones: ['+1555000111', '+1555000222']
}
});
console.log(`Added: ${data.added}, Skipped: ${data.skipped}`);
// Or add existing contacts by ID
await zernio.broadcasts.addBroadcastRecipients({
path: { broadcastId: 'BROADCAST_ID' },
body: {
contactIds: ['contact_1', 'contact_2']
}
});
// Or auto-populate from your broadcast's segment filters (e.g., all contacts tagged "vip")
await zernio.broadcasts.addBroadcastRecipients({
path: { broadcastId: 'BROADCAST_ID' },
body: { useSegment: true }
});# Add WhatsApp recipients by phone number (auto-creates contacts)
response = client.broadcasts.add_broadcast_recipients(
broadcast_id='BROADCAST_ID',
phones=['+1555000111', '+1555000222']
)
print(f"Added: {response.added}, Skipped: {response.skipped}")
# Or add existing contacts by ID
client.broadcasts.add_broadcast_recipients(
broadcast_id='BROADCAST_ID',
contact_ids=['contact_1', 'contact_2']
)
# Or auto-populate from your broadcast's segment filters
client.broadcasts.add_broadcast_recipients(
broadcast_id='BROADCAST_ID',
use_segment=True
)# Add WhatsApp recipients by phone number
curl -X POST "https://zernio.com/api/v1/broadcasts/BROADCAST_ID/recipients" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"phones": ["+1555000111", "+1555000222"]}'
# Or add existing contacts by ID
curl -X POST "https://zernio.com/api/v1/broadcasts/BROADCAST_ID/recipients" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"contactIds": ["contact_1", "contact_2"]}'Send a Broadcast
Triggers immediate delivery of the WhatsApp template messages to all recipients:
const { data } = await zernio.broadcasts.sendBroadcast({
path: { broadcastId: 'BROADCAST_ID' }
});
console.log(`Sent: ${data.sent}, Failed: ${data.failed}`);response = client.broadcasts.send_broadcast(
broadcast_id='BROADCAST_ID'
)
print(f"Sent: {response.sent}, Failed: {response.failed}")curl -X POST "https://zernio.com/api/v1/broadcasts/BROADCAST_ID/send" \
-H "Authorization: Bearer YOUR_API_KEY"Schedule a Broadcast
Schedule the WhatsApp broadcast for a future time. Zernio sends the template messages automatically at the scheduled time:
await zernio.broadcasts.scheduleBroadcast({
path: { broadcastId: 'BROADCAST_ID' },
body: { scheduledAt: '2025-02-01T10:00:00.000Z' }
});client.broadcasts.schedule_broadcast(
broadcast_id='BROADCAST_ID',
scheduled_at='2025-02-01T10:00:00.000Z'
)curl -X POST "https://zernio.com/api/v1/broadcasts/BROADCAST_ID/schedule" \
-H "Authorization: Bearer YOUR_API_KEY" \
-H "Content-Type: application/json" \
-d '{"scheduledAt": "2025-02-01T10:00:00.000Z"}'