# Baatzo API v1 > The Baatzo API sends one approved Utility or Authentication WhatsApp template to one number, reads how it went, exports a workspace's data, and posts a signed webhook each time a message's status changes. It is part of the Starter, Growth and Pro plans; sandbox keys (bz_test_) work on every plan. On Pro, the full API adds contacts and consent, templates (read), campaigns, Marketing sends and event webhooks. The MCP server at https://api.baatzo.com/mcp offers the same operations to AI assistants, with OAuth sign-in or an API key. Baatzo is a WhatsApp Business Platform product of Aashita Technosoft Private Limited, Jaipur (https://baatzo.com). Base URL: https://api.baatzo.com. JSON over HTTPS. Every error is `{ "code", "message", "details" }`: act on `code`; `message` is for people and may change. API messages appear in the contact's chat in Baatzo, marked API, and cost what any message costs: Meta's charge, which Meta bills to the business's own WhatsApp Business Account directly, plus Baatzo's fee from the workspace's message credit. On Starter and Growth, API v1 sends Utility and Authentication templates only. The full API (contacts, templates, campaigns, Marketing sends, event webhooks) is part of Pro (and Enterprise): on another plan its operations answer 403 `plan_required` with `details.upgradeTo`, and a sandbox key gets 403 `forbidden` with reason `sandbox_scope`. The full API's fields are snake_case, money is a string (paise for Baatzo's fee, micro-rupees for Meta's estimated charge), lists take `cursor` and `limit` (1 to 100) and answer `next_cursor`, bodies are strict, and an id that is not a UUID is 404 `not_found`. ## Authentication 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. Roll a key to replace it without downtime: the new key has the same scopes and the old one works for 24 hours more. Send it as a bearer token: `Authorization: Bearer bz_live_<8-character prefix>_<32 characters>` (`bz_test_` for a sandbox key). Scopes: - `messages:send`: POST /v1/messages - `messages:read`: GET /v1/messages/{id}; on the MCP server, the templates and the credit balance - `contacts:read`: GET /v1/contacts/{id}/consent-certificate; on the MCP server, listing contacts - `contacts:write`: on the MCP server, adding and updating contacts - `data:export`: POST /v1/exports, GET /v1/exports and the download - On Pro, `contacts:read` and `contacts:write` also cover the full API's contact, tag, list and consent routes - `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 stats - `campaigns:write` (Pro): create, estimate, schedule, send and cancel campaigns - `messages:send_marketing` (Pro): POST /v1/messages with a Marketing template, beside `messages:send` - `webhooks:manage` (Pro): choose the webhook's event types, read the delivery log and replay a delivery A key cannot be made with a Pro scope on another plan; after a downgrade its Pro operations answer 403 `plan_required`. A missing scope is 403 `forbidden` with reason `missing_scope`. A new key sends only to Indian numbers. The workspace Owner can add countries to a key in Settings, Developers. Limits: 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_limited` with a Retry-After header in seconds. Every answer carries RateLimit-Limit, RateLimit-Remaining and RateLimit-Reset (also as X-RateLimit-*) for the key's bucket, and X-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: `Idempotency-Key` is required on every send. The same key with the same body gets the first answer, with nothing sent twice; keys are kept for 24 hours. The same key with a different body is 422 `idempotency_key_reused`. On the full API, every POST that creates something or reserves credit (adding a contact, recording consent, creating, scheduling and sending a campaign, a replay) needs an `Idempotency-Key` of 8 to 100 letters, digits, - or _ (400 `idempotency_key_invalid` otherwise; 409 `idempotency_in_progress` while the first request still runs). 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 the answer is 503 `retry_later`, and your login flow sends a fresh code. ## Libraries Both read the key you pass in, keep `Idempotency-Key` for you (pass your own to make a retry safe), and check webhook signatures. - Node.js 20 or later: `npm install @baatzo/node` (https://www.npmjs.com/package/@baatzo/node). `const baatzo = new Baatzo(process.env.BAATZO_API_KEY)`; `await baatzo.messages.send({ to, template: { name, language }, variables: { body: { ... } }, reference }, { idempotencyKey })`; `await baatzo.messages.get(id)`; `verifyWebhook(rawBody, header, secret)`. - Python 3.10 or later: `pip install baatzo` (https://pypi.org/project/baatzo/). `baatzo = Baatzo(api_key=os.environ["BAATZO_API_KEY"])`; `baatzo.messages.send(to=..., template={"name": ..., "language": ...}, variables={"body": {...}}, reference=..., idempotency_key=...)`; `baatzo.messages.get(id)`; `verify_webhook(raw_body, header, secret)`. - Version 0.2.0 of both, with the full API (contacts, tags, lists, templates, campaigns, webhook events) and typed event payloads, is coming; until then call the full API over HTTPS. - Any other language: plain HTTPS and JSON, below. ## Endpoints - [POST /v1/messages](https://api.baatzo.com/docs#send): send one approved Utility or Authentication template to one number (a Marketing template on Pro, see Marketing sends). Needs `messages:send` and an `Idempotency-Key` header. Body: `to` (E.164, such as +919829012345), `template.name`, `template.language` (exactly as in Baatzo, such as en or en_IN), optional `from` (Meta's phone number ID, needed only when the workspace has more than one number for the template), `variables.body` (each variable by name or number; for Authentication `{ "code": "482913" }`, 1 to 15 letters and digits), `variables.header.document` (`{ "link", "filename" }`, https only), `variables.header.image` and `variables.header.video` (`{ "link" }`, https only, for Utility and Marketing templates), `variables.buttons` (`{ "index", "url" }` or `{ "index", "copy_code" }`) and `reference` (your own id, up to 64 characters). Answers 201 `accepted` (WhatsApp took it), 201 `failed` or `withheld` (refused for good, with WhatsApp's code and a plain explanation in English and Hindi, no Baatzo fee), 202 `queued` (a Utility send WhatsApp asked to wait; Baatzo retries it) or 202 `unknown` (WhatsApp did not answer in time; the webhook settles it; do not send again with a new Idempotency-Key). - [GET /v1/messages/{id}](https://api.baatzo.com/docs#read): a message's status, `status_rank`, `reference`, template and category, times (`accepted_at`, `sent_at`, `delivered_at`, `read_at`, `failed_at`), charge and, on failure, the error with a plain explanation. Needs `messages:read`. `charge.baatzo_fee_paise` is Baatzo's fee, taken from message credit only when Meta charges for the message; `charge.meta_charge_estimate` is an estimate from Meta's published rate, because Meta bills its own charge directly. - [POST /v1/exports](https://api.baatzo.com/docs#exports): export the whole workspace into 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). Needs `data:export` and an `Idempotency-Key` of 8 to 100 letters, digits, - or _. Answers 202 with the export queued; the key's creator gets an email when it is ready. One export of everything is built at a time (409 `export_in_progress`). - [GET /v1/exports](https://api.baatzo.com/docs#exports): list exports, newest first, with cursor pagination (`cursor`, `limit`). Needs `data:export`. - [GET /v1/exports/{id}/download](https://api.baatzo.com/docs#exports): download a ready export. A ready export can be downloaded for 7 days, then it is deleted (410 `export_expired`); while it is still queued or building the answer is 409 `export_not_ready`. Needs `data:export`. - [GET /v1/contacts/{id}/consent-certificate](https://api.baatzo.com/docs#consent): 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. Needs `contacts:read`. It is for your records, not legal advice. - [POST /mcp](https://api.baatzo.com/docs/mcp.html): the Baatzo MCP server (see below). ## Full API endpoints (Pro) - [GET /v1/contacts](https://api.baatzo.com/docs#contacts): contacts newest first, with `total`; filters `q` (name or number), `tag_id`, `list_id`, `marketing` and `utility` (`granted`, `withdrawn` or `none`). Needs `contacts:read`. - [POST /v1/contacts](https://api.baatzo.com/docs#contacts): add a contact, or update the one with the same `phone` (E.164) or `bsuid`, with `name`, `username`, `attributes` (custom fields by key), `tag_ids`, `list_ids` and up to 2 `consent` grants. Needs `contacts:write` and an `Idempotency-Key`. Answers 201 `{ "created": true, "contact", "consent_records" }` for a new contact, 200 for an update. - [GET /v1/contacts/{id}](https://api.baatzo.com/docs#contacts), [PATCH /v1/contacts/{id}](https://api.baatzo.com/docs#contacts) (fields left out keep their value; `tag_ids` and `list_ids` replace; a number another contact has is 409 `contact_exists`; never changes consent) and [DELETE /v1/contacts/{id}](https://api.baatzo.com/docs#contacts) (204; DPDP erasure: the contact, its tags, lists and files go; its opt-outs stay as hashes so it is never messaged again). - [POST /v1/contacts/{id}/consents](https://api.baatzo.com/docs#consent-rules): one consent record, `purpose` `marketing` or `utility`, `action` `grant` or `withdraw`. A grant needs `collected_via` (`web_form`, `paper_form`, `whatsapp`, `ctwa_ad`, `in_person`, `phone_call` or `other`), `statement` (the words the person agreed to, up to 1,000 characters) and `captured_at` (ISO 8601 with its offset); `ip` and `note` are optional. A grant after an opt-out needs evidence dated after it, else 422 `consent_refused`. Needs `contacts:write` and an `Idempotency-Key`; answers 201. - [POST /v1/contacts/{id}/opt-out](https://api.baatzo.com/docs#consent-rules): what a STOP reply does; `purpose` `marketing` (default), `utility` or `all`. - [GET /v1/tags](https://api.baatzo.com/docs#tags-lists) and [GET /v1/lists](https://api.baatzo.com/docs#tags-lists) (`kind` `static` or `segment`), up to 500 each; [POST /v1/contacts/{id}/tags](https://api.baatzo.com/docs#tags-lists) `{ "tag_ids" }`, DELETE /v1/contacts/{id}/tags/{tagId}, [POST /v1/contacts/{id}/lists](https://api.baatzo.com/docs#tags-lists) `{ "list_id" }` and DELETE /v1/contacts/{id}/lists/{listId}, each answering the contact. - [GET /v1/templates](https://api.baatzo.com/docs#templates): templates newest first, read only, filters `status`, `category`, `name`, `language`; each with `variables`, header, body, footer, buttons and `sendable`. GET /v1/templates/{id} and GET /v1/templates/{id}/status (the review state alone). Needs `templates:read`. - [GET /v1/campaigns](https://api.baatzo.com/docs#campaigns) (`status` `all`, `draft`, `active` or `finished`) and GET /v1/campaigns/{id}, GET /v1/campaigns/{id}/stats. Needs `campaigns:read`. - [POST /v1/campaigns](https://api.baatzo.com/docs#campaigns): a draft from `name`, `template_id` or `template { name, language }`, an `audience` of `list_ids`, `segment_ids` and `tag_ids` (at least one), `variables` (each `{ "source": "name" | "phone" | "field" | "text", "field", "fallback" }`), optional `from` and `header_media { link, file_name }`. Sends nothing. Authentication templates are refused. Needs `campaigns:write` and an `Idempotency-Key`; answers 201 with `variables_needed`. - [POST /v1/campaigns/{id}/estimate](https://api.baatzo.com/docs#campaigns): who can get it, who is left out and why, Meta's charge at most (an estimate), Baatzo's fee with GST, the limit forecast, quiet hours and whether the credit covers it. - [POST /v1/campaigns/{id}/schedule](https://api.baatzo.com/docs#campaigns) (`scheduled_at`, 5 minutes to 90 days ahead) and [POST /v1/campaigns/{id}/send](https://api.baatzo.com/docs#campaigns) (held 30 seconds, status `held`): both need an `Idempotency-Key`, reserve the credit for every recipient (402 `insufficient_credit`, or `start_anyway: true` to start with the part the credit covers) and answer 422 `nothing_to_send` when nobody can get it. [POST /v1/campaigns/{id}/cancel](https://api.baatzo.com/docs#campaigns): a draft, held or scheduled campaign ends at once; a sending one stops after what Meta has. A step the status does not allow is 409 `campaign_state` with `details.reason`. - [GET /v1/webhook-endpoint](https://api.baatzo.com/docs#webhook-api) and [PUT /v1/webhook-endpoint/events](https://api.baatzo.com/docs#webhook-api) (`{ "events": [...] }`); GET /v1/webhook-deliveries (30 days, filters `status`, `from`, `to`), GET /v1/webhook-deliveries/{id} (with the payload and the first 2 KB of the answer) and POST /v1/webhook-deliveries/{id}/replay (202; needs an `Idempotency-Key`). Needs `webhooks:manage`. The address and the signing secret are set only in the web app, never with a key. ## Marketing sends (Pro) [POST /v1/messages](https://api.baatzo.com/docs#marketing) sends a Marketing template when the key also has `messages:send_marketing`. The person needs a marketing consent recorded beforehand (422 `consent_required`); an opt-out refuses (422 `recipient_opted_out`, `details.purpose` `marketing`); +1 numbers are refused (422 `recipient_not_allowed`, `details.reason` `us_number`); a number that was not on WhatsApp in the last 30 days is refused (422 `recipient_unreachable`); outside the workspace's sending hours (9 am to 9 pm India time unless changed), as campaigns keep them, it is refused (409 `quiet_hours`, `details.retry_at` the next start). It goes through Meta's Marketing Messages API with the Cloud API as fallback. Baatzo's fee is ₹0.05 a marketing message, from the message credit; Meta bills its own charge directly. ## Sandbox Build and test before the 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 and exports need a live key (another scope is refused with 400 `sandbox_scope_not_allowed`, and other operations answer 403 `forbidden` with reason `sandbox_scope`). POST /v1/messages takes the same body and headers, checks them the same way and answers at once with `"sandbox": true` and a made-up wamid starting `wamid.SANDBOX`. Nothing reaches WhatsApp and nothing is charged; the message does not appear in the inbox. Any template name is accepted; if the workspace has a template with that name and language, its category is checked as on a live key, and Marketing is refused. The status webhook then gets `message.sent` after about 1 second, `message.delivered` after about 3 and `message.read` after about 8, signed like live events, with `"sandbox": true` in the event and in `data`, and the header `Baatzo-Sandbox: 1`. A sandbox key reads sandbox messages only, and a live key never sees them. Opt-outs are not checked. Sandbox messages are kept 30 days. Test numbers: +919000000001 gets `message.failed` after about 2 seconds with Meta's error 131026 (message undeliverable); +919000000002 is sent and delivered, never read; any other number is sent, delivered and read. ## MCP server and OAuth - [MCP server guide](https://api.baatzo.com/docs/mcp.html): address `https://api.baatzo.com/mcp`, Streamable HTTP, stateless (GET and DELETE answer 405). It is API v1 over the Model Context Protocol, with the same scopes, limits and error codes, and it sees only the one Baatzo workspace. Tools: `list_templates` (`messages:read`; templates with category, status, the variables each needs and whether the API can send it), `send_template_message` (`messages:send`; the body of POST /v1/messages plus a required `idempotency_key`), `get_message_status` (`messages:read`), `list_contacts` (`contacts:read`; newest first, with marketing and utility consent; `search` matches a name or number), `upsert_contact` (`contacts:write`; adds a contact by E.164 number or updates its name and custom fields; never records consent) `get_credit_balance` (`messages:read`; Baatzo message credit in paise and rupees), and on Pro `get_contact` (`contacts:read`; one contact by `contact_id`), `list_campaigns` (`campaigns:read`) and `create_campaign` (`campaigns:write`; a draft from a template and an audience, sends nothing). A refusal is a tool error whose structured content is `{ "error": { "code", "message", "details" } }`. Sign in with OAuth: give the app only the address. Apps that follow the MCP authorization specification (Claude, ChatGPT, Cursor and others) open Baatzo in the browser; an Owner or Admin with two-step verification, in a workspace on Starter, Growth or Pro, chooses the workspace and the permissions and presses Allow. The app sends to Indian numbers only and never to the sandbox. It stays connected until removed in Settings, Developers, Connected apps, or 30 days unused; access lasts an hour at a time and renews itself. For app builders: protected resource metadata at `/.well-known/oauth-protected-resource/mcp` (a 401 from /mcp names it in WWW-Authenticate), authorization server metadata at `/.well-known/oauth-authorization-server`, dynamic registration at `POST /oauth/register` (public clients only, https redirect URIs or http to localhost, 127.0.0.1 or [::1]), the authorization code grant with PKCE (S256) and `resource=https://api.baatzo.com/mcp`. Refresh tokens rotate on every use; presenting a used one again disconnects the app. `POST /oauth/revoke` disconnects it. Or use a key: `Authorization: Bearer `, a sandbox key first, with only the scopes the assistant's tools need. Claude Code: `claude mcp add --transport http baatzo https://api.baatzo.com/mcp`. ## Webhooks Set one HTTPS URL for the 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. Event types: `message.sent`, `message.delivered`, `message.read`, `message.failed`, and `webhook.test` from the test button. The body is `{ "id", "type", "created_at", "data": { "message_id", "reference", "wamid", "status", "status_rank", "charge", "error" } }`. Payloads never carry template variables or codes. Event webhooks (Pro): the same endpoint can also take `message.received` (a customer's message: `message_id`, `wamid`, `conversation_id`, `phone_number_id`, `contact`, `type`, `text`, `reply_to_wamid`, `received_at`), `contact.opted_in` (`contact`, `purpose`), `contact.opted_out` (`contact`, `purpose`, `opted_out_at`), `template.status_changed` (`template_id`, `name`, `language`, `category`, `previous_status`, `status`, `reason`), `campaign.finished` (`campaign_id`, `name`, `status` completed, cancelled or failed, `failure_reason`, `finished_at`, `stats`), `payment_link.paid` (`payment_link_id`, `reference_id`, `description`, `amount_paise`, `paid_amount_paise`, `method`, `razorpay_payment_id`, `contact`, `conversation_id`, `paid_at`) and `conversation.assigned` (`conversation_id`, `contact`, `assignee`, `method` manual, automation or round_robin, `assigned_at`). `contact` is `{ "id", "phone", "bsuid", "name" }`. A new endpoint takes the four status events; choose others in Settings, Developers or with PUT /v1/webhook-endpoint/events. An event is written only when the endpoint subscribes to its type and the plan has the full API. Same signature, retries, delivery log and replay as the status events. 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 whose `status_rank` is lower than one you already have. Baatzo calls only public addresses and does not follow redirects. Replays from the delivery log carry the same event id, a fresh timestamp and the header `Baatzo-Replay: 1`. Signature: the header is `Baatzo-Signature: t=,v1=`, where v1 is the HMAC-SHA256 of the timestamp, a full stop and the raw body, keyed with the `whsec_` secret. Check it on the raw bytes before parsing the JSON, compare in constant time, and refuse a timestamp more than 5 minutes off. For 24 hours after a secret is rotated, the header carries two v1 values: accept the event if either matches. - [verify-signature.js](https://api.baatzo.com/docs/verify-signature.js): the check in Node.js, ready to copy; also [Python](https://api.baatzo.com/docs/verify-signature.py) and [PHP](https://api.baatzo.com/docs/verify-signature.php). ## Reference - [API reference](https://api.baatzo.com/docs): the human-readable reference, with every error code and status. - [OpenAPI document](https://api.baatzo.com/docs/openapi.json): API v1, the full API and every webhook event as OpenAPI 3.1; import this address into Postman. - [Everything in one file](https://api.baatzo.com/docs/llms-full.txt): the three pages below in full, as Markdown. - Pages as Markdown: [reference](https://api.baatzo.com/docs/index.md), [MCP server](https://api.baatzo.com/docs/mcp.md), [changelog and version policy](https://api.baatzo.com/docs/changelog.md). Statuses, with `status_rank`: `queued` (0 to 1, not with WhatsApp yet), `unknown` (1, WhatsApp did not answer in time), `accepted` (2), `held` (3, WhatsApp is checking it before delivery), `sent` (4), `delivered` (5), `read` (6), `failed` and `withheld` (7, not delivered; withheld messages are held back by Meta and not charged). Error codes: `unauthenticated` 401, `forbidden` 403, `plan_required` 403 (the workspace is on Template Studio), `idempotency_key_required` 400, `invalid_request` 422, `template_not_found` 404, `template_not_approved` 422, `category_not_allowed` 422 (Marketing, including a template Meta has moved to Marketing, without `messages:send_marketing`), `recipient_not_allowed` 422, `recipient_opted_out` 422, `insufficient_credit` 402, `sending_paused` 409, `idempotency_key_reused` 422, `request_in_progress` 409 (POST /v1/messages), `rate_limited` 429, `retry_later` 503, `not_found` 404, `idempotency_key_invalid` 400 and `idempotency_in_progress` 409 (POST /v1/exports), `export_in_progress` 409, `export_not_ready` 409, `export_expired` 410; and for the full API `contact_exists` 409 (another contact has that number), `consent_refused` 422 (a grant after an opt-out without newer evidence), `consent_required` 422 (a Marketing send with no marketing consent recorded), `recipient_unreachable` 422 (a Marketing send to a number not on WhatsApp in the last 30 days), `campaign_state` 409 (the campaign's status does not allow the step) `nothing_to_send` 422 (nobody in the campaign's audience can get it) and `quiet_hours` 409 (a Marketing send outside the workspace's sending hours; `details.retry_at`). `plan_required` also answers a full API operation on a plan without it, and `category_not_allowed` a Marketing template without `messages:send_marketing`. Web app codes come back as these, with the original in `details.reason`. ## Optional - [Baatzo website for AI assistants](https://baatzo.com/llms.txt): what Baatzo is, its plans and prices in INR, and every page. - [Developers page](https://baatzo.com/developers): Embedded Signup, how Baatzo handles Meta's webhooks, and agency workspaces.