Baatzo API v1
Send one approved WhatsApp template to one number, read how it went, and get a signed webhook each time its status changes. On Pro, the full API also manages contacts and their consent, reads templates, runs campaigns, sends Marketing templates and posts webhooks for events such as a customer's message or an opt-out. API messages appear in the contact's chat in Baatzo, marked API, and cost what any message costs: Meta's charge, which Meta bills you directly, plus Baatzo's fee from your message credit.
View as Markdown Open in ChatGPT Open in Claude
- Base URL
https://api.baatzo.com- Plans
- API v1 on Starter, Growth and Pro; the full API on Pro; the sandbox on every plan
- Format
- JSON over HTTPS
API v1 (sending Utility and Authentication templates, reading them, the status webhook, exports and the consent certificate) works on Starter, Growth and Pro. Contacts, templates, campaigns, Marketing sends and event webhooks are the full API, part of Pro. On another plan they answer 403 plan_required.
Keys and scopes
An Owner or Admin with two-step verification on makes keys in the Baatzo web app, under Settings, Developers. A key is shown once: keep it on your server, never in an app or a web page. Baatzo stores only a hash of it, so a lost key is revoked and replaced. A revoked key stops working on the next request. To replace a key without downtime, press Roll beside it: you get a new key with the same name, scopes and countries, and the old one keeps working for 24 hours. A key can be rolled once.
Send it in the Authorization header:
Authorization: Bearer bz_live_K7Q2M9XA_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
| Scope | Plans | Allows |
|---|---|---|
messages:send | Starter, Growth, Pro | POST /v1/messages with a Utility or Authentication template |
messages:read | Starter, Growth, Pro | GET /v1/messages/{id}; on the MCP server, the templates and the credit balance |
contacts:read | Starter, Growth, Pro | GET /v1/contacts/{id}/consent-certificate; on the MCP server, listing contacts. On Pro also GET /v1/contacts, GET /v1/contacts/{id}, GET /v1/tags and GET /v1/lists |
contacts:write | Starter, Growth, Pro | On the MCP server, adding and updating contacts. On Pro also adding, changing, tagging, listing, opting out and erasing contacts, and recording consent |
data:export | Starter, Growth, Pro | POST /v1/exports, GET /v1/exports and the download |
templates:read | Pro | GET /v1/templates, GET /v1/templates/{id} and its status |
campaigns:read | Pro | GET /v1/campaigns, GET /v1/campaigns/{id} and its results |
campaigns:write | Pro | Creating, estimating, scheduling, sending and cancelling campaigns |
messages:send_marketing | Pro | POST /v1/messages with a Marketing template, to contacts with a recorded marketing consent. The key needs messages:send too |
webhooks:manage | Pro | Choosing the webhook's event types, reading the delivery log and replaying deliveries |
A key cannot be made with a Pro scope on another plan. After a downgrade, the key stays but its Pro operations answer 403 plan_required until the plan returns. A key without the scope an operation needs gets 403 forbidden with details.reason missing_scope.
A new key sends only to Indian numbers. The workspace Owner can add countries to a key in Settings, Developers. This stops bots that request codes to numbers abroad from running up your Meta bill.
Sandbox keys start bz_test_ and work everywhere, on every plan (see Sandbox).
Limits and retries
- Each key may send 10 messages a second, with bursts to 20, and read 20 times a second. Over that, the answer is
429 rate_limitedwith aRetry-Afterheader in seconds. Every answer to a request with a valid key carriesRateLimit-Limit,RateLimit-RemainingandRateLimit-Reset(also asX-RateLimit-*) for the key's bucket (a 401 has no bucket to report, and carriesWWW-Authenticate: Bearer), andX-Request-Id, which support asks for. - More than 20 requests a minute with a wrong key from one address are refused the same way for a minute.
Idempotency-Keyis required on every send. Send the same key and the same body again (after a timeout, say) and you get the first answer, with nothing sent twice. Keys are kept for 24 hours.- On the full API, every POST that creates something or reserves credit needs an
Idempotency-Keyof 8 to 100 letters, digits,-or_: adding a contact, recording consent, creating, scheduling and sending a campaign, and a replay. The full API's writes take from the key's send limit, its reads from the read limit. - Baatzo retries a Utility or Marketing send itself when WhatsApp asks it to wait. It never retries an Authentication send, because it does not keep the code: on a temporary error you get
503 retry_later, and your login flow sends a fresh code.
Sandbox
Build and test before your WhatsApp number is connected or Meta has approved anything. In Settings, Developers, create a sandbox key: it is free on every plan, up to 5 per workspace, and starts bz_test_. It holds messages:send and messages:read only; contacts, consent certificates, exports and the whole full API need a live key.
Authorization: Bearer bz_test_K7Q2M9XA_xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
POST /v1/messagestakes the same body and headers, checks them the same way (Idempotency-Key, the number, the key's countries, rate limits) and answers at once with"sandbox": trueand a made-upwamidstartingwamid.SANDBOX. Nothing reaches WhatsApp and nothing is charged; the message does not appear in the inbox.- Any template name is accepted, so you can start before approval. If your workspace has a template with that name and language, its category is checked as on a live key: Marketing is refused. Variables are checked for shape only.
- Your status webhook then gets
message.sentafter about 1 second,message.deliveredafter about 3 andmessage.readafter about 8, signed exactly like live events, with"sandbox": truein the event and indata, and the headerBaatzo-Sandbox: 1. GET /v1/messages/{id}with the sandbox key reads sandbox messages only; a live key never sees them, and a sandbox key never sees live ones.- Opt-outs are not checked and no contact is made. Sandbox messages are kept 30 days.
| Send to | What happens |
|---|---|
+919000000001 | message.failed after about 2 seconds with Meta's error 131026 (message undeliverable) and its plain explanation. |
+919000000002 | Sent and delivered, never read. |
| Any other number | Sent, delivered and read. |
Import into Postman
The whole of API v1 is one OpenAPI 3.1 document. In Postman, click Use resources or import in the sidebar, then the Import tab, and enter this address:
https://api.baatzo.com/docs/openapi.json
Set the collection's bearer token to a sandbox key and give each send a new Idempotency-Key.
Send a message
Sends one approved template to one number. Needs messages:send. A Marketing template also needs messages:send_marketing, on Pro (see Marketing sends).
| Field | Type | Notes |
|---|---|---|
to | string | Required. The number in E.164, such as +919829012345. |
template.name | string | Required. An approved template of your workspace: Utility or Authentication, or Marketing with messages:send_marketing. |
template.language | string | Required. The template's language code exactly as in Baatzo, such as en or en_IN. |
from | string | Meta's phone number ID of the sending number. Needed only when the workspace has more than one number for the template. |
variables.body | object | Each variable by name (or number, for a numbered template). For Authentication: { "code": "482913" }, 1 to 15 letters and digits. Up to 1,024 characters each, with no line breaks or tabs. |
variables.header.document | object | { "link", "filename" } for a template with a document header, such as a PDF report. The link must be https, at most 2,048 characters, with no user name or password. WhatsApp fetches the file; Baatzo does not. |
variables.header.image, variables.header.video | object | { "link" } for a Utility or Marketing template with an image or video header. The same rules for the link as for a document. |
variables.buttons | array | { "index", "url" } for a URL button with a variable, { "index", "copy_code" } for a copy-code button. Without index, the position in the array. |
reference | string | Your own id, up to 64 characters, returned in reads and webhooks. |
A login code
curl https://api.baatzo.com/v1/messages \
-H "Authorization: Bearer $BAATZO_API_KEY" \
-H "Idempotency-Key: login-88213-1" \
-H "Content-Type: application/json" \
-d '{ "to": "+919829012345",
"template": { "name": "login_code", "language": "en" },
"variables": { "body": { "code": "482913" } },
"reference": "login-88213" }'
// Node.js 18 or later: fetch is built in.
const res = await fetch('https://api.baatzo.com/v1/messages', {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.BAATZO_API_KEY}`,
'Idempotency-Key': 'login-88213-1',
'Content-Type': 'application/json',
},
body: JSON.stringify({
to: '+919829012345',
template: { name: 'login_code', language: 'en' },
variables: { body: { code: '482913' } },
reference: 'login-88213',
}),
});
const answer = await res.json();
if (!res.ok) throw new Error(`${answer.code}: ${answer.message}`);
# Python 3.9 or later, with: pip install requests
import os
import requests
res = requests.post(
"https://api.baatzo.com/v1/messages",
headers={
"Authorization": f"Bearer {os.environ['BAATZO_API_KEY']}",
"Idempotency-Key": "login-88213-1",
},
json={
"to": "+919829012345",
"template": {"name": "login_code", "language": "en"},
"variables": {"body": {"code": "482913"}},
"reference": "login-88213",
},
timeout=30,
)
answer = res.json()
if not res.ok:
raise RuntimeError(f"{answer['code']}: {answer['message']}")
<?php // PHP 8.0 or later, with the curl extension. $ch = curl_init('https://api.baatzo.com/v1/messages'); curl_setopt_array($ch, [ CURLOPT_POST => true, CURLOPT_RETURNTRANSFER => true, CURLOPT_TIMEOUT => 30, CURLOPT_HTTPHEADER => [ 'Authorization: Bearer ' . getenv('BAATZO_API_KEY'), 'Idempotency-Key: login-88213-1', 'Content-Type: application/json', ], CURLOPT_POSTFIELDS => json_encode([ 'to' => '+919829012345', 'template' => ['name' => 'login_code', 'language' => 'en'], // PHP writes an empty array as [], which the API refuses: leave out a part with no variables. 'variables' => ['body' => ['code' => '482913']], 'reference' => 'login-88213', ]), ]); $raw = curl_exec($ch); if ($raw === false) { throw new RuntimeException(curl_error($ch)); } $answer = json_decode($raw, true); if (curl_getinfo($ch, CURLINFO_RESPONSE_CODE) >= 400) { throw new RuntimeException("{$answer['code']}: {$answer['message']}"); }
A report with a PDF
// Node.js 18 or later: fetch is built in. const res = await fetch('https://api.baatzo.com/v1/messages', { method: 'POST', headers: { Authorization: `Bearer ${process.env.BAATZO_API_KEY}`, 'Idempotency-Key': `report-${report.id}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ to: '+919829012345', template: { name: 'mock_test_report', language: 'en' }, variables: { body: { parent_name: 'Asha', student: 'Ravi' }, header: { document: { link: report.pdfUrl, filename: 'Mock test 4.pdf' } }, }, reference: `report-${report.id}`, }), }); const answer = await res.json(); if (res.status === 429 || res.status === 503) { // Wait Retry-After seconds. For a 503 on a code, send a new code. }
# Python 3.9 or later, with: pip install requests res = requests.post( "https://api.baatzo.com/v1/messages", headers={ "Authorization": f"Bearer {os.environ['BAATZO_API_KEY']}", "Idempotency-Key": f"report-{report.id}", }, json={ "to": "+919829012345", "template": {"name": "mock_test_report", "language": "en"}, "variables": { "body": {"parent_name": "Asha", "student": "Ravi"}, "header": {"document": {"link": report.pdf_url, "filename": "Mock test 4.pdf"}}, }, "reference": f"report-{report.id}", }, timeout=30, ) answer = res.json() if res.status_code in (429, 503): ... # Wait Retry-After seconds. For a 503 on a code, send a new code.
// The same curl call as the login code, with this body. $body = json_encode([ 'to' => '+919829012345', 'template' => ['name' => 'mock_test_report', 'language' => 'en'], 'variables' => [ 'body' => ['parent_name' => 'Asha', 'student' => 'Ravi'], 'header' => ['document' => ['link' => $report->pdfUrl, 'filename' => 'Mock test 4.pdf']], ], 'reference' => "report-{$report->id}", ]); // On 429 or 503, wait Retry-After seconds. For a 503 on a code, send a new code.
Answers
201 Created
{ "id": "0193f6c2-7a1e-7c55-9d1b-4f2b6c1d9a10", "status": "accepted", "reference": "login-88213" }
| HTTP | status | Means |
|---|---|---|
| 201 | accepted | WhatsApp took the message. Webhooks follow as it is sent, delivered and read. |
| 201 | failed, withheld | WhatsApp refused it for good. error carries WhatsApp's code and a plain explanation in English and Hindi. No Baatzo fee. |
| 202 | queued | A Utility or Marketing send WhatsApp asked to wait. Baatzo retries it; the webhook tells you how it ends. |
| 202 | unknown | WhatsApp did not answer in time. It may still deliver; the webhook settles it. Do not send again with a new Idempotency-Key. |
Read a message
Any message sent through the API in your workspace. Needs messages:read.
curl https://api.baatzo.com/v1/messages/0193f6c2-7a1e-7c55-9d1b-4f2b6c1d9a10 \
-H "Authorization: Bearer $BAATZO_API_KEY"
{ "id": "0193f6c2-7a1e-7c55-9d1b-4f2b6c1d9a10",
"status": "delivered", "status_rank": 5, "reference": "login-88213",
"template": { "name": "login_code", "language": "en", "category": "authentication" },
"created_at": "2027-01-28T09:15:00.120Z",
"times": { "accepted_at": "…", "sent_at": "…", "delivered_at": "…", "read_at": null, "failed_at": null },
"charge": { "category": "authentication", "baatzo_fee_paise": 2, "state": "chargeable",
"meta_charge_estimate": { "amount_micro_rupees": "115000", "is_estimate": true } },
"error": null }
Meta bills its own charge to your WhatsApp Business account; meta_charge_estimate is an estimate from Meta's published rate. baatzo_fee_paise is Baatzo's fee, taken from your message credit only when Meta charges for the message.
Export everything
Your whole workspace in one zip: contacts, their consent history and the whole consent ledger, messages, templates (JSON), every invoice and credit note (PDF), a campaigns summary and the automations (JSON). It is the same export as Settings, Export everything. Needs data:export. The POST needs an Idempotency-Key of 8 to 100 letters, digits, - or _; it answers 202 with the export queued, and the key's creator gets an email when it is ready. A ready export can be downloaded for 7 days, then it is deleted. One export of everything is built at a time (409 export_in_progress).
curl -X POST https://api.baatzo.com/v1/exports \
-H "Authorization: Bearer $BAATZO_API_KEY" -H "Idempotency-Key: export-2027-02-01"
202 Accepted
{ "export": { "id": "0193f6d1-…", "status": "queued", "everything": true, "contacts": null,
"created_at": "…", "completed_at": null, "expires_at": null, "download_url": null } }
curl https://api.baatzo.com/v1/exports -H "Authorization: Bearer $BAATZO_API_KEY"
{ "exports": [ { "id": "0193f6d1-…", "status": "ready", "download_url": "/v1/exports/0193f6d1-…/download", … } ],
"next_cursor": null }
Consent certificate
A PDF of one contact's consent ledger: who they are, their consent now, and every opt-in and opt-out with its date, source, the statement shown, the IP address and the person or key that recorded it where Baatzo has them, each with its record id. Needs contacts:read. It is for your records, not legal advice. The workspace's whole ledger is a CSV in the web app (Settings, Business, Your data).
The full API (Pro)
Contacts, templates, campaigns, Marketing sends and event webhooks are the full API. They are part of the Pro plan (and Enterprise). On Starter or Growth every full API operation answers 403 plan_required with details.upgradeTo, the plan to move to; a sandbox key gets 403 forbidden with details.reason sandbox_scope.
- Every rule is the web app's: the same consent checks, the same opt-out list, the same credit and the same audit log, with the key as the actor. The workspace is always the key's, never one named in the body.
- Fields are snake_case. Money is a string: paise for Baatzo's fee, micro-rupees for Meta's charge, which is always an estimate because Meta bills you directly.
- Lists take
cursorandlimit(1 to 100) and answernext_cursor,nullon the last page. An id that is not a UUID is404 not_found, like an id from another workspace. - Bodies are strict: an unknown field is
422 invalid_request. Codes from the web app come back as the codes in the error list, with the original indetails.reasonwhere it says more.
Contacts
Reads need contacts:read, changes contacts:write. GET /v1/contacts lists newest first and filters by q (a name or a number), tag_id, list_id, marketing and utility (granted, withdrawn or none); it also answers total.
POST /v1/contacts adds a contact or updates the one with the same number. It needs an Idempotency-Key, and answers 201 with "created": true for a new contact, 200 for an update. Consent grants in the same request are recorded after the contact is saved.
| Field | Type | Notes |
|---|---|---|
phone | string | E.164, such as +919829012345. Give phone or bsuid. |
bsuid | string | WhatsApp's user ID, for a person known by username only. |
name, username | string | Up to 120 and 40 characters. null clears one. |
attributes | object | Custom field values by field key, such as { "city": "Jaipur" }: text up to 500 characters, a number, or null to clear. |
tag_ids, list_ids | array | Up to 50 ids each, of tags and lists that exist. |
consent | array | Up to 2 grants, each as in Recording consent. |
curl https://api.baatzo.com/v1/contacts \
-H "Authorization: Bearer $BAATZO_API_KEY" \
-H "Idempotency-Key: signup-asha-20261128" \
-H "Content-Type: application/json" \
-d '{ "phone": "+919829012345", "name": "Asha Verma",
"attributes": { "city": "Jaipur" },
"consent": [ { "purpose": "marketing", "collected_via": "web_form",
"statement": "Send me offers on WhatsApp.",
"captured_at": "2026-11-28T15:30:00+05:30", "ip": "203.0.113.7" } ] }'
201 Created
{ "created": true,
"contact": { "id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "name": "Asha Verma", "phone": "+919829012345",
"source": "api", "consent": { "marketing": "granted", "utility": "none", "marketing_opted_out_at": null },
"us_number": false, "unreachable_until": null, "tags": [], "lists": [], … },
"consent_records": [ { "id": "0193b1c3-…", "purpose": "marketing", "action": "grant", "source": "api",
"collected_via": "web_form", "captured_at": "2026-11-28T10:00:00.000Z",
"recorded_at": "2026-11-28T10:00:01.000Z" } ] }
// Node.js 18 or later: fetch is built in. const res = await fetch('https://api.baatzo.com/v1/contacts', { method: 'POST', headers: { Authorization: `Bearer ${process.env.BAATZO_API_KEY}`, 'Idempotency-Key': `signup-${form.id}`, 'Content-Type': 'application/json', }, body: JSON.stringify({ phone: form.phone, name: form.name, consent: [{ purpose: 'marketing', collected_via: 'web_form', statement: form.consentText, // the exact words beside the tick box captured_at: new Date(form.submittedAt).toISOString(), ip: form.ip, }], }), }); const answer = await res.json(); if (!res.ok) throw new Error(`${answer.code}: ${answer.message}`);
PATCH /v1/contacts/{id} changes phone, bsuid, name, username, attributes, tag_ids or list_ids; a field you leave out keeps its value, and tag_ids and list_ids replace the contact's tags and lists. A number another contact already has is 409 contact_exists. Consent is never changed here.
DELETE /v1/contacts/{id} answers 204. It is the DPDP erasure the web app does: the contact, its tags, lists and files go for good. Its opt-outs stay as one-way hashes, so a person who said stop is never messaged again, even if they are added once more. Their consent records stay in the ledger without the contact.
Recording consent
Consent is per purpose, marketing or utility, and lives in a ledger that is only ever added to. A send never records consent for Marketing: record it first, from your own evidence. POST /v1/contacts/{id}/consents takes one record with action grant or withdraw, needs contacts:write and an Idempotency-Key, and answers 201 with the record and the contact.
| Field | Notes |
|---|---|
purpose | Required. marketing or utility. |
action | Required on /consents. grant or withdraw. Each item of consent in POST /v1/contacts is a grant. |
collected_via | Required for a grant. How the person agreed: web_form, paper_form, whatsapp, ctwa_ad (a Click-to-WhatsApp ad), in_person, phone_call or other. |
statement | Required for a grant. The words the person agreed to, up to 1,000 characters, exactly as they saw or heard them. |
captured_at | Required for a grant. When they agreed, ISO 8601 with its offset, such as 2026-11-28T15:30:00+05:30. A withdrawal without it is dated now. |
ip | The IPv4 or IPv6 address they agreed from, when you have one. |
note | Up to 500 characters, for your own records. |
- A grant after an opt-out needs evidence dated after that opt-out. Otherwise the answer is
422 consent_refused, and nothing is recorded. FromPOST /v1/contacts, the contact is still saved, anddetailscarriescontact_idandcreated. POST /v1/contacts/{id}/opt-outdoes what a STOP reply does.purposeismarketing(the default),utilityorall; it answers200with the records and the contact.- Each record shows
sourceapiand the key that made it, in the web app and on the consent certificate.
Tags and lists
GET /v1/tags answers up to 500 tags by name, each with its number of contacts; GET /v1/lists up to 500 lists, each with kind static or segment (a saved filter). Tags and lists are made in the web app. POST /v1/contacts/{id}/tags takes { "tag_ids": [...] } (1 to 50), POST /v1/contacts/{id}/lists takes { "list_id" }; each change answers 200 with the contact.
Templates
Read only, with templates:read: templates are written and submitted to Meta in the web app, where the rules check and the category advice run. The list is newest first and filters by status (draft, pending, approved, rejected, paused, disabled or all, the default), category, name and language.
Each template carries the version Meta reviewed: its category, status, quality, variables (the names to fill, or code for Authentication), header, body, footer and buttons, and sendable: true when POST /v1/messages can send it. GET /v1/templates/{id}/status answers the review state alone, with requested_category, rejected_reason and paused_until. The template.status_changed event tells you when Meta decides.
curl "https://api.baatzo.com/v1/templates?status=approved&category=marketing" \
-H "Authorization: Bearer $BAATZO_API_KEY"
{ "templates": [ { "id": "0193a1b2-3c4d-7e5f-8a6b-7c8d9e0f1a2b", "name": "diwali_offer", "language": "en",
"category": "marketing", "status": "approved", "quality": "green", "sendable": true,
"variables": ["name", "code"], "header": { "format": "image", "text": null },
"body": "Hi {{name}}, use {{code}} for 20% off this Diwali.", … } ],
"next_cursor": null }
Campaigns
The campaign builder of the web app, step by step. Reads need campaigns:read, the rest campaigns:write. Everything the web app checks is checked: the template is approved and not Authentication (send codes one by one with POST /v1/messages), Marketing goes only to contacts with a marketing consent and no later opt-out and never to +1 numbers, quiet hours and the ban shield apply, and the credit for every recipient is reserved before anything goes.
POST /v1/campaignsmakes a draft and sends nothing. It needs anIdempotency-Keyand answers201with the campaign andvariables_needed. Givename,template_idortemplate { name, language }, anaudienceof at least one oflist_ids,segment_idsandtag_ids(up to 20 each), andvariables: each variable as{ "source": "name" | "phone" | "field" | "text", "field", "fallback" }. A recipient whose variable stays empty is skipped, never sent a broken message.frompicks the sending number by Meta's phone number ID;header_media { link, file_name }fills a media header.POST /v1/campaigns/{id}/estimateanswers who can get it, who is left out and why (duplicates,no_identity,opted_out,no_consent,us_number,unreachable,missing_variables), Meta's charge at most (an estimate), Baatzo's fee with GST, the messaging limit forecast, quiet hours and whether your credit covers it. It changes nothing.POST /v1/campaigns/{id}/schedulewithscheduled_at(ISO 8601 with its offset, 5 minutes to 90 days ahead), orPOST /v1/campaigns/{id}/sendto send now. Both need anIdempotency-Key, confirm the estimate and reserve the credit. When the credit does not cover everyone, the answer is402 insufficient_credit; with"start_anyway": trueit starts with the part the credit covers. When nobody can get it,422 nothing_to_send.- Send now holds the campaign for 30 seconds (status
held, untilheld_until).POST /v1/campaigns/{id}/cancelin that time stops it with nothing sent. A draft or a scheduled campaign also ends at once and its credit goes back; one that is sending stops after the messages Meta already has. GET /v1/campaigns/{id}/statsanswers the counters the web app shows: recipients, queued, sent, delivered, read, replied, held, failed, withheld, skipped and cancelled, with reasons, Baatzo's fee and Meta's charge so far.campaign.finishedposts them when it ends.
A campaign in a state that does not allow the step is 409 campaign_state, with the reason in details.reason (such as campaign_locked within 5 minutes of its start). A paused number or a spending limit reached is 409 sending_paused. Statuses: draft, held, scheduled, preparing, sending, paused, paused_no_credit, cancelling, cancelled, completed and failed. GET /v1/campaigns filters by status: draft, active, finished or all.
curl https://api.baatzo.com/v1/campaigns \
-H "Authorization: Bearer $BAATZO_API_KEY" \
-H "Idempotency-Key: diwali-2026-draft" \
-H "Content-Type: application/json" \
-d '{ "name": "Diwali offer 2026",
"template": { "name": "diwali_offer", "language": "en" },
"audience": { "list_ids": ["0193b1c2-0000-7a00-8000-0000000000a1"] },
"variables": { "name": { "source": "name", "fallback": "there" },
"code": { "source": "text", "fallback": "DIWALI20" } },
"header_media": { "link": "https://cdn.example.com/diwali.jpg" } }'
201 Created
{ "campaign": { "id": "0193c0d1-2e3f-7a4b-8c5d-6e7f8a9b0c1d", "status": "draft", … },
"variables_needed": ["name", "code"] }
// Node.js 18 or later. Estimate, then schedule for 10 am India time.
const call = (path, body, idempotencyKey) =>
fetch(`https://api.baatzo.com/v1${path}`, {
method: 'POST',
headers: {
Authorization: `Bearer ${process.env.BAATZO_API_KEY}`,
'Content-Type': 'application/json',
...(idempotencyKey ? { 'Idempotency-Key': idempotencyKey } : {}),
},
body: JSON.stringify(body ?? {}),
}).then(async (res) => {
const answer = await res.json();
if (!res.ok) throw new Error(`${answer.code}: ${answer.message}`);
return answer;
});
const { estimate } = await call(`/campaigns/${id}/estimate`);
console.log(estimate.eligible, estimate.excluded, estimate.credit.enough);
await call(`/campaigns/${id}/schedule`, { scheduled_at: '2026-12-05T10:00:00+05:30' }, `diwali-2026-schedule`);
Marketing sends
On Pro, POST /v1/messages sends a Marketing template to one person when the key has messages:send_marketing as well as messages:send. The body is the same as any send. A template with an image or video header takes variables.header.image or variables.header.video as { "link" }.
- The person needs a marketing consent recorded beforehand (Recording consent), else
422 consent_required. A send never records it. - Someone who opted out of marketing, or whose number is on the opt-out list from an erased contact, is
422 recipient_opted_outwithdetails.purposemarketing. - Meta delivers no marketing to +1 numbers:
422 recipient_not_allowedwithdetails.reasonus_number. - A number that was not on WhatsApp when Baatzo last tried waits 30 days:
422 recipient_unreachable. - Marketing goes only in the workspace's sending hours (Settings, Business; 9 am to 9 pm India time unless changed), as campaigns do: outside them
409 quiet_hours, withdetails.retry_atthe next start. Utility and Authentication are never held. - Without
messages:send_marketing, a Marketing template is422 category_not_allowed; on a plan without the full API,403 plan_required. - It goes through Meta's Marketing Messages API, with the Cloud API as the fallback, as campaigns do. Baatzo's fee for a marketing message is ₹0.05, taken from your message credit; Meta bills its own charge to you directly.
curl https://api.baatzo.com/v1/messages \
-H "Authorization: Bearer $BAATZO_API_KEY" \
-H "Idempotency-Key: diwali-asha-1" \
-H "Content-Type: application/json" \
-d '{ "to": "+919829012345",
"template": { "name": "diwali_offer", "language": "en" },
"variables": { "body": { "name": "Asha", "code": "DIWALI20" },
"header": { "image": { "link": "https://cdn.example.com/diwali.jpg" } } },
"reference": "diwali-asha" }'
201 Created
{ "id": "0193f6c2-…", "status": "accepted", "reference": "diwali-asha" }
Status events
Set one HTTPS URL for your workspace in Settings, Developers. Baatzo posts an event each time a message sent through the API is sent, delivered, read or fails. The page shows the signing secret once (it starts whsec_), sends a test event, and lists 30 days of deliveries.
POST https://your-server.example/baatzo-webhook
Baatzo-Signature: t=1801123456,v1=5257a869e7ecebeda32affa62cdca3fa51cad7e77a0e56ff536d0ce8e108d8bd
Content-Type: application/json
{ "id": "evt_0193f6c4-…", "type": "message.delivered",
"created_at": "2027-01-28T09:15:02Z",
"data": { "message_id": "0193f6c2-…", "reference": "login-88213",
"wamid": "wamid.HBgMOTE5ODI5MDEyMzQ1FQIAERgS…",
"status": "delivered", "status_rank": 5,
"charge": { "category": "authentication", "baatzo_fee_paise": 2, "state": "chargeable" },
"error": null } }
- Types:
message.sent,message.delivered,message.read,message.failed, andwebhook.testfrom the test button. - Answer any 2xx within 5 seconds. Otherwise Baatzo retries after 1, 5, 15 and 30 minutes, then 1, 2, 4 and 8 hours, and a last time 24 hours after the first attempt. Owners and Admins get one email a day while deliveries fail.
- Events can arrive out of order or more than once. Drop a repeat by
id, and ignore a status whosestatus_rankis lower than one you already have. - Payloads never carry template variables or codes.
- Baatzo calls only public addresses: a URL that resolves to a private, loopback or link-local address is refused, and redirects are not followed.
- A new endpoint takes the four
message.*status events. Choose others in Settings, Developers, or withPUT /v1/webhook-endpoint/events.
Event webhooks (Pro)
On Pro, the same endpoint can also take events about your workspace, not only about API messages. Each one is signed with the same Baatzo-Signature, retried on the same schedule, kept in the same 30-day delivery log and can be replayed. Baatzo writes an event only when your endpoint subscribes to its type and your plan has the full API, so an event you did not choose is never sent later. The body is always { "id", "type", "created_at", "data" }; drop a repeat by id. No payload carries a template variable, a code or a hash.
| Type | Fires when |
|---|---|
message.received | A customer sends a message to one of your numbers. Once per WhatsApp message, even when Meta repeats its webhook. |
contact.opted_in | A contact's consent for marketing or utility becomes granted, from any source: the web app, an import, the API or a WhatsApp reply. |
contact.opted_out | A contact withdraws consent for marketing or utility, such as by replying STOP. |
template.status_changed | Meta's review moves a template: approved, rejected, paused, disabled or moved to another category. |
campaign.finished | A campaign completes, is cancelled or fails, with its results at that moment. |
payment_link.paid | Razorpay reports one of your payment links paid in full. Payment links in Baatzo are coming soon; the event fires once they are live. |
conversation.assigned | A person, a keyword rule or the round robin gives a chat to a team member. |
message.received
{ "id": "evt_0193c2a0-1b2c-7d3e-8f4a-5b6c7d8e9f01", "type": "message.received",
"created_at": "2026-11-28T10:05:00.000Z",
"data": { "message_id": "0193c2a0-1b2c-7d3e-8f4a-5b6c7d8e9f00",
"wamid": "wamid.HBgMOTE5ODI5MDEyMzQ1FQIAEhgg…",
"conversation_id": "0193b9e0-1111-7222-8333-444455556666",
"phone_number_id": "109876543210987",
"contact": { "id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma" },
"type": "text", "text": "Is the offer on till Sunday?",
"reply_to_wamid": null, "received_at": "2026-11-28T10:04:59.000Z" } }
text is the message's text or a media file's caption, else null; reply_to_wamid is the message it answers, if any.
contact.opted_in
{ "id": "evt_0193c2a1-…", "type": "contact.opted_in", "created_at": "2026-11-28T10:00:01.000Z",
"data": { "contact": { "id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma" },
"purpose": "marketing" } }
contact.opted_out
{ "id": "evt_0193c2a2-…", "type": "contact.opted_out", "created_at": "2026-11-28T12:00:00.000Z",
"data": { "contact": { "id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma" },
"purpose": "marketing", "opted_out_at": "2026-11-28T11:59:58.000Z" } }
template.status_changed
{ "id": "evt_0193c2a3-…", "type": "template.status_changed", "created_at": "2026-11-21T08:00:01.000Z",
"data": { "template_id": "0193a1b2-3c4d-7e5f-8a6b-7c8d9e0f1a2b", "name": "diwali_offer", "language": "en",
"category": "marketing", "previous_status": "pending", "status": "approved", "reason": null } }
reason carries Meta's reason for a rejection, a pause or a new category, where Meta gives one.
campaign.finished
{ "id": "evt_0193c2a4-…", "type": "campaign.finished", "created_at": "2026-12-05T11:20:00.000Z",
"data": { "campaign_id": "0193c0d1-2e3f-7a4b-8c5d-6e7f8a9b0c1d", "name": "Diwali offer 2026",
"status": "completed", "failure_reason": null, "finished_at": "2026-12-05T11:20:00.000Z",
"stats": { "recipients": 1200, "sent": 1180, "delivered": 1150, "read": 900, "replied": 64,
"failed": 20, "skipped": 0, "failed_by_reason": { "131026": 20 },
"baatzo_fee_paise": "5750",
"meta_charge_estimate": { "amount_micro_rupees": "992565000", "is_estimate": true }, … } } }
status is completed, cancelled or failed; stats has the same fields as GET /v1/campaigns/{id}/stats.
payment_link.paid
{ "id": "evt_0193c2a5-…", "type": "payment_link.paid", "created_at": "2026-11-28T13:00:00.000Z",
"data": { "payment_link_id": "0193c2a5-0000-7000-8000-0000000000aa", "reference_id": "order-1042",
"description": "Order 1042", "amount_paise": "149900", "paid_amount_paise": "149900",
"method": "upi", "razorpay_payment_id": "pay_PQ1234567890ab",
"contact": { "id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma" },
"conversation_id": "0193b9e0-1111-7222-8333-444455556666", "paid_at": "2026-11-28T12:59:58.000Z" } }
conversation.assigned
{ "id": "evt_0193c2a6-…", "type": "conversation.assigned", "created_at": "2026-11-28T10:06:00.000Z",
"data": { "conversation_id": "0193b9e0-1111-7222-8333-444455556666",
"contact": { "id": "0193b1c2-4d5e-7f60-8a1b-2c3d4e5f6a70", "phone": "+919829012345", "bsuid": null, "name": "Asha Verma" },
"assignee": { "id": "0193a000-aaaa-7bbb-8ccc-dddddddddddd", "name": "Ravi" },
"method": "round_robin", "assigned_at": "2026-11-28T10:06:00.000Z" } }
method is manual, automation or round_robin.
Manage the webhook
On Pro, with webhooks:manage. The address and the signing secret can be set only in the web app, by an Owner or Admin with two-step verification, never with an API key: a key can choose the events and replay them, never send them to another server.
GET /v1/webhook-endpointanswers the endpoint (nulluntil an address is set), itsevents, and every event type with its label and whether your plan can take it.PUT /v1/webhook-endpoint/eventswith{ "events": [...] }replaces the list: at least one type, each once. Before an address is set it is404 not_found.GET /v1/webhook-deliverieslists the last 30 days, newest first, filtered bystatus(PENDING,RETRYING,DELIVEREDorFAILED),fromandto.GET /v1/webhook-deliveries/{id}adds thepayloadand the first 2 KB of your server's answer.POST /v1/webhook-deliveries/{id}/replayneeds anIdempotency-Keyand answers202with{ "queued": 1, "delivery_ids": [...] }. Replaying a time range stays in the web app.
curl -X PUT https://api.baatzo.com/v1/webhook-endpoint/events \
-H "Authorization: Bearer $BAATZO_API_KEY" -H "Content-Type: application/json" \
-d '{ "events": ["message.sent", "message.delivered", "message.read", "message.failed",
"message.received", "contact.opted_out", "campaign.finished"] }'
Verify the signature
v1 is the HMAC-SHA256 of the timestamp, a full stop and the raw body, keyed with your secret, in hex. Check it on the raw bytes before parsing the JSON, compare in constant time, and refuse a timestamp more than 5 minutes off. After you rotate the secret, both the old and the new one sign for 24 hours, so the header carries two v1 values: accept the event if either matches.
// Verifying a Baatzo status webhook (API v1). Node.js 18 or later, no packages.
//
// Baatzo sends Baatzo-Signature: t=1801123456,v1=<hex>[,v1=<hex>]
// where each v1 is the HMAC-SHA256 of "<t>.<raw body>" keyed with your signing secret (whsec_...).
// During a secret rotation the header carries two v1 values for 24 hours; accept the request if any matches.
// Check the RAW body, byte for byte, before parsing it as JSON.
const { createHmac, timingSafeEqual } = require('crypto');
const TOLERANCE_SECONDS = 5 * 60;
/**
* True when the header is a valid Baatzo signature of rawBody under secret, made at most 5 minutes
* from now. rawBody is a Buffer or string, exactly as received.
*/
function verifyBaatzoSignature(rawBody, header, secret, now = Date.now()) {
if (typeof header !== 'string' || typeof secret !== 'string') return false;
let t = null;
const signatures = [];
for (const part of header.split(',')) {
const i = part.indexOf('=');
const k = part.slice(0, i).trim();
const v = part.slice(i + 1).trim();
if (k === 't' && /^\d{1,12}$/.test(v)) t = Number(v);
if (k === 'v1' && /^[0-9a-f]{64}$/.test(v)) signatures.push(Buffer.from(v, 'hex'));
}
if (t === null || !signatures.length) return false;
if (Math.abs(Math.floor(now / 1000) - t) > TOLERANCE_SECONDS) return false;
const body = Buffer.isBuffer(rawBody) ? rawBody : Buffer.from(String(rawBody), 'utf8');
const expected = createHmac('sha256', secret).update(`${t}.`).update(body).digest();
return signatures.some((s) => s.length === expected.length && timingSafeEqual(s, expected));
}
module.exports = { verifyBaatzoSignature };
// Express example: keep the raw body for the check.
//
// app.post('/baatzo-webhook', express.raw({ type: 'application/json' }), (req, res) => {
// if (!verifyBaatzoSignature(req.body, req.get('Baatzo-Signature'), process.env.BAATZO_WEBHOOK_SECRET)) {
// return res.status(400).end();
// }
// const event = JSON.parse(req.body.toString('utf8'));
// // Drop a repeat by event.id; ignore a status older than one you already have (event.data.status_rank).
// res.status(200).end(); // answer within 5 seconds, then do the work
// });
# Verifying a Baatzo status webhook (API v1). Python 3.9 or later, no packages.
#
# Baatzo sends Baatzo-Signature: t=1801123456,v1=<hex>[,v1=<hex>]
# where each v1 is the HMAC-SHA256 of "<t>.<raw body>" keyed with your signing secret (whsec_...).
# During a secret rotation the header carries two v1 values for 24 hours; accept the request if any matches.
# Check the RAW body, byte for byte, before parsing it as JSON.
import hashlib
import hmac
import re
import time
TOLERANCE_SECONDS = 5 * 60
def verify_baatzo_signature(raw_body, header, secret, now=None):
"""True when header is a valid signature of raw_body (bytes), made at most 5 minutes from now."""
if not isinstance(header, str) or not secret:
return False
t, signatures = None, []
for part in header.split(","):
k, _, v = (x.strip() for x in part.partition("="))
if k == "t" and re.fullmatch(r"[0-9]{1,12}", v):
t = int(v)
if k == "v1" and re.fullmatch(r"[0-9a-f]{64}", v):
signatures.append(v)
if t is None or not signatures:
return False
if abs(int(time.time() if now is None else now) - t) > TOLERANCE_SECONDS:
return False
expected = hmac.new(secret.encode(), f"{t}.".encode() + raw_body, hashlib.sha256).hexdigest()
return any(hmac.compare_digest(s, expected) for s in signatures)
# Flask example: request.get_data() is the raw body.
#
# @app.post("/baatzo-webhook")
# def baatzo_webhook():
# raw = request.get_data()
# if not verify_baatzo_signature(raw, request.headers.get("Baatzo-Signature"), os.environ["BAATZO_WEBHOOK_SECRET"]):
# return "", 400
# event = json.loads(raw)
# # Drop a repeat by event["id"]; ignore a status older than one you already have (status_rank).
# return "", 200 # answer within 5 seconds, then do the work
<?php
// Verifying a Baatzo status webhook (API v1). PHP 8.0 or later, no packages.
//
// Baatzo sends Baatzo-Signature: t=1801123456,v1=<hex>[,v1=<hex>]
// where each v1 is the HMAC-SHA256 of "<t>.<raw body>" keyed with your signing secret (whsec_...).
// During a secret rotation the header carries two v1 values for 24 hours; accept the request if any matches.
// Check the RAW body, byte for byte, before parsing it as JSON.
const BAATZO_TOLERANCE_SECONDS = 300;
/** True when $header is a valid Baatzo signature of $rawBody, made at most 5 minutes from now. */
function verify_baatzo_signature(string $rawBody, ?string $header, string $secret, ?int $now = null): bool
{
if ($header === null || $secret === '') {
return false;
}
$t = null;
$signatures = [];
foreach (explode(',', $header) as $part) {
[$k, $v] = array_map('trim', array_pad(explode('=', $part, 2), 2, ''));
if ($k === 't' && preg_match('/^[0-9]{1,12}$/D', $v)) {
$t = (int) $v;
}
if ($k === 'v1' && preg_match('/^[0-9a-f]{64}$/D', $v)) {
$signatures[] = $v;
}
}
if ($t === null || $signatures === []) {
return false;
}
if (abs(($now ?? time()) - $t) > BAATZO_TOLERANCE_SECONDS) {
return false;
}
$expected = hash_hmac('sha256', $t . '.' . $rawBody, $secret);
foreach ($signatures as $signature) {
if (hash_equals($expected, $signature)) {
return true;
}
}
return false;
}
// A webhook script: php://input is the raw body.
//
// $raw = file_get_contents('php://input');
// if (!verify_baatzo_signature($raw, $_SERVER['HTTP_BAATZO_SIGNATURE'] ?? null, getenv('BAATZO_WEBHOOK_SECRET'))) {
// http_response_code(400);
// exit;
// }
// $event = json_decode($raw, true);
// // Drop a repeat by $event['id']; ignore a status older than one you already have (status_rank).
// http_response_code(200); // answer within 5 seconds, then do the work
The same files: verify-signature.js, verify-signature.py and verify-signature.php.
Delivery log and replay
Settings, Developers lists the last 30 days of deliveries: the time, the event, the wamid, your server's HTTP status, how long it took and the attempts. Each one opens to show the payload, the status code and the first 2 KB of your server's answer.
- Replay sends one delivery again, or every delivery of a time range (at most 1,000; a status filter, such as only the failed ones, narrows it). A replay is the same event (the same
id) signed with a fresh timestamp and sent with the headerBaatzo-Replay: 1, once, with no retries. Deduplicating byidkeeps it harmless if you had the event already. - The log and replays need the same role as the webhook settings: Owner or Admin. On Pro, a key with
webhooks:managereads the log and replays one delivery too (Manage the webhook).
Error codes
Every error is { "code", "message", "details" }. Act on code; message is for people and may change.
| Code | HTTP | When |
|---|---|---|
unauthenticated | 401 | The key is missing, malformed, unknown or revoked. |
forbidden | 403 | The key lacks the scope (details.reason is missing_scope), a sandbox key tried something other than sending and reading messages (sandbox_scope), or the workspace is suspended or closing. |
plan_required | 403 | The workspace is on Template Studio, or a full API operation, a Marketing send or an event type beyond message status needs Pro (details.upgradeTo names the plan). Keys stay after a downgrade, but those requests fail until the plan returns. |
idempotency_key_required | 400 | A POST that needs an Idempotency-Key has none: a send, an export, adding a contact, recording consent, creating, scheduling or sending a campaign, or a replay. |
invalid_request | 422 | A field fails validation. details lists each { field, message }. |
template_not_found | 404 | No template with that name and language. |
template_not_approved | 422 | The template is not approved now (details.status says what it is). |
category_not_allowed | 422 | The template is Marketing (including one Meta has moved to Marketing) and the key has no messages:send_marketing, or the sandbox was asked to send Marketing. |
recipient_not_allowed | 422 | The number's country is not allowed for this key (details.country), or a Marketing send to a +1 number (details.reason us_number). |
recipient_opted_out | 422 | The person withdrew consent for messages like this (details.purpose is marketing for a Marketing send). |
insufficient_credit | 402 | Your message credit cannot cover Baatzo's fee, for one message or for every recipient of a campaign. Nothing was sent. Top up in Billing. |
sending_paused | 409 | The number cannot send now; details.reason says why (for example reconnect_needed, meta_payment or, for a campaign, spend_limit_reached). |
idempotency_key_reused | 422 | The same Idempotency-Key with a different body. |
request_in_progress | 409 | POST /v1/messages: the first request with this Idempotency-Key is still running. Try again in a moment. |
rate_limited | 429 | Over the key's limit, or too many wrong keys from your address. See Retry-After. |
retry_later | 503 | An Authentication send hit a temporary WhatsApp error. Send a new code. |
not_found | 404 | No such message, contact, tag, list, template, campaign, export or delivery in this workspace, or no webhook address set yet. |
idempotency_key_invalid | 400 | POST /v1/exports and the full API: the Idempotency-Key is not 8 to 100 letters, digits, - or _. |
idempotency_in_progress | 409 | POST /v1/exports and the full API: the first request with this key is still running. |
export_in_progress | 409 | An export of everything is being built already. |
export_not_ready | 409 | The export is still queued or building. Try again in a minute. |
export_expired | 410 | The export's 7 days are over, or it could not be made. Make a new one. |
contact_exists | 409 | PATCH /v1/contacts/{id}: another contact already has that number or WhatsApp user ID. |
consent_refused | 422 | A consent grant after an opt-out has no evidence dated after that opt-out (details.reason is reopt_in_needs_evidence or consent_before_opt_out). From POST /v1/contacts, the contact is still saved (details.contact_id). |
consent_required | 422 | A Marketing send to a person with no marketing consent recorded. Record it first. |
recipient_unreachable | 422 | A Marketing send to a number that was not on WhatsApp when Baatzo last tried. Marketing to it waits 30 days. |
campaign_state | 409 | The campaign's status does not allow this step, such as scheduling one already sent or changing one within 5 minutes of its start (details.reason). |
nothing_to_send | 422 | Scheduling or sending a campaign that nobody in its audience can get. details.estimate says why. |
quiet_hours | 409 | A Marketing send outside the workspace's sending hours, which campaigns keep too. details.retry_at is when they start again; details.start and details.end are the hours, India time. |
Statuses
| status | status_rank | Means |
|---|---|---|
queued | 0 to 1 | Not with WhatsApp yet. |
unknown | 1 | WhatsApp did not answer in time; a webhook settles it. |
accepted | 2 | WhatsApp took it. |
held | 3 | WhatsApp is checking it before delivery. |
sent | 4 | Sent to the person's phone. |
delivered | 5 | On the person's phone. |
read | 6 | Opened. |
failed, withheld | 7 | Not delivered. Withheld messages are held back by Meta and not charged. |