WhatsApp messaging API
Base URL: https://chatsa.co/api/v1
Send and receive WhatsApp messages through a business's number connected in ChatSa. ChatSa carries the messages over Meta's WhatsApp Cloud API, keeps the full history (every message shows in the business's ChatSa inbox) and sends every inbound message and status to your webhooks.
All paths below are under https://chatsa.co/api/v1/whatsapp. Authenticate with an API key, a Connect token, a chatbot key or an account key that has the scope each call names (see Authentication). chatbot_id may be left out when the key is limited to exactly one chatbot, except in the bodies of PUT /mode, PUT /threads/{phone}/control, POST /display-name and POST /voice, which always need it.
Who answers: AI or Team only#
Each number runs in one of two modes:
ai: ChatSa's AI answers customers (and your API sends work too).api("Team only"): ChatSa's AI never replies. Every inbound message is saved and sent to your webhooks, and your people or your own software answer.
Read the mode with GET /status; change it with:
PUT /api/v1/whatsapp/mode
Authorization: Bearer csa_…
{ "chatbot_id": "6f1c…", "mode": "api" }
Scope whatsapp:manage. Answers { "data": { "mode": "api" } }, or 503 unavailable when nothing could be changed.
Number status#
GET /status?chatbot_id= (scope whatsapp:read):
{
"data": {
"capabilities": ["messages", "voice_notes", "voice_api", "takeover", "coexistence"],
"chatbot_id": "6f1c…",
"chatbot_name": "Acme Plumbing",
"mode": "api",
"connected": true,
"phone_number": "14155550123",
"display_name": "Acme Plumbing",
"quality_rating": "GREEN",
"messaging_limit": "TIER_1K",
"coexistence": null
}
}
coexistence is null, except for a number that keeps the WhatsApp Business app (see the partner API):
"coexistence": {
"active": true,
"onboarded_at": "2026-11-29T18:00:00Z",
"sync_requested": true,
"sync_error": null,
"history": { "status": "importing", "progress": 40, "messages": 812 },
"contacts": { "synced": 240 },
"last_app_message_at": "2026-11-30T09:12:00Z"
}
history.status is waiting, importing, done or declined.
Sending a message#
POST /messages (scope whatsapp:send). The Idempotency-Key header is required (at most 100 characters, unique per send).
POST /api/v1/whatsapp/messages
Authorization: Bearer csa_…
Idempotency-Key: visit-8812-confirm
Content-Type: application/json
{
"chatbot_id": "6f1c…",
"to": "14155550199",
"type": "text",
"text": "Hi Jordan, your technician arrives at 3 pm.",
"sender": { "name": "Taylor Brooks", "email": "taylor@acmeplumbing.com" },
"contact": { "name": "Jordan Lee", "company": "Lee Dental" },
"reference": { "type": "job", "id": "8812" }
}
201:
{
"data": {
"id": "b4e1…",
"wa_message_id": "wamid.HBgL…",
"conversation_id": "0a9c…",
"status": "sent",
"window_open_until": "2026-11-30T21:04:00Z"
}
}
| Field | Notes |
|---|---|
to | The customer's number, with its country code. E.164 digits; +1 415 555 0199 style is accepted. |
type | text, template, buttons, link, image, document, video or audio |
text | text: up to 4,096 characters. The body of buttons and link: up to 1,024. |
sender | Optional. Shown in ChatSa's inbox ("Taylor Brooks via API"). |
contact | Optional. Names the customer's ChatSa contact. |
reference | Optional { type, id } of your own, echoed on message.sent and message.status. |
The 24-hour window#
WhatsApp lets a business send free-form messages only within 24 hours of the customer's last message to that number. Inside the window you may send text, buttons, link and media. Outside it, only an approved template goes; anything else answers 409 window_closed. window_open_until in the answer (and in threads) tells you when the window closes.
Reply buttons and link buttons#
Inside the window:
{
"type": "buttons",
"to": "14155550199",
"text": "Does 3 pm still work for you?",
"buttons": [
{ "id": "job-8812:yes", "title": "Yes, 3 pm works" },
{ "id": "job-8812:later", "title": "Later today" }
],
"footer": "Acme Plumbing"
}
buttons: 1 to 3 reply buttons, each with your ownid(up to 256 characters) and atitle(up to 20). Ids and titles must be unique. A tap comes back asmessage.receivedwithbutton: { id, title }.link: one button that opens a public https address:"link": { "text": "Track your visit", "url": "https://acmeplumbing.com/v/8812" }(text up to 20).headerandfooter(up to 60 characters each) are optional for both.
Templates#
{
"type": "template",
"to": "14155550199",
"template": {
"name": "visit_reminder",
"language": "en_US",
"body": ["Jordan", "3 pm"],
"header": ["Tomorrow"],
"buttons": [{ "index": 1, "text": "8812" }],
"quick_replies": [{ "index": 0, "payload": "job-8812:confirm" }]
}
}
- The template must be
APPROVEDin that language: otherwise422 template_not_approved(withtemplate_status). bodyfills{{1}}…{{n}}in order;headerfills a text header's variable;buttonsgives the suffix of each URL button that takes one;quick_repliessets the payload returned when a quick-reply button is tapped (without it, WhatsApp returns the button's text). Wrong counts or indexes answer422 invalid_template_params.header_mediais required by, and only allowed for, templates whose header is an image, document or video:"header_media": { "type": "document", "link": "https://files.example.com/quote-8812.pdf", "filename": "Quote.pdf" }. Itstypemust match the template's header, and ChatSa fetches the file as it does any media. Such a template takes noheadervalues.- Read a template's variable counts with
GET /templates.
Media#
{
"type": "document",
"to": "14155550199",
"media": {
"link": "https://files.example.com/quote-8812.pdf",
"filename": "Quote 8812.pdf",
"caption": "Your quote",
"mime_type": "application/pdf"
}
}
ChatSa fetches link once from its servers (https only, public hosts only, at most three redirects, 30 seconds), keeps a private copy and uploads it to WhatsApp, so a short-lived signed link is fine. Limits:
| Type | Formats | Size |
|---|---|---|
image | JPEG, PNG | 5 MB |
document | PDF, Word, Excel, PowerPoint, plain text | 100 MB |
video | MP4, 3GPP | 16 MB |
audio | AAC, MP4 audio, MPEG, AMR, Ogg | 16 MB |
The file's type comes from mime_type, else the file name, else the server's Content-Type; an image or a PDF must really be one. Audio takes no caption. "voice": true on audio converts it and sends it as a voice note. Errors: 422 media_unreachable, 413 media_too_large, 422 media_type_not_allowed.
Idempotency#
The same Idempotency-Key with the same key, within 24 hours, answers the first result again (with the header Idempotent-Replayed: true) and sends nothing, whatever the body says: use a new key for every new message. A refusal (bad request, window closed, opted out…) frees the key, so retrying with the same key is safe. A send whose delivery is unknown (502 send_failed with delivery_unknown: true) keeps the key, so a retry never sends twice. A key still being processed answers 409 idempotency_in_progress.
Opt-outs#
When a customer writes a stop word (stop, unsubscribe, and their Arabic equivalents), ChatSa records the opt-out and sends contact.opted_out; start opts back in (contact.opted_in). A template to an opted-out number answers 409 opted_out. Free text is allowed only inside a window the customer opened by writing again after opting out.
Send errors#
| Status | Code | Meaning |
|---|---|---|
| 400 | idempotency_key_required, invalid_request | Missing header or a bad field (the message names it) |
| 403 | forbidden | Missing scope, chatbot not on the key, inactive workspace, or a plan without WhatsApp |
| 403 | sending_paused | This business's business-initiated messages are paused (see below) |
| 404 | not_found | No such chatbot |
| 409 | window_closed, opted_out, idempotency_in_progress | See above |
| 413 / 422 | media_too_large, media_unreachable, media_type_not_allowed | See Media |
| 422 | invalid_number, undeliverable | Not a valid number, or not on WhatsApp |
| 422 | invalid_link | A link button's url isn't a public https address |
| 422 | template_not_approved, invalid_template_params | See Templates |
| 429 | rate_limited, daily_cap_reached | Slow down (Retry-After), or this business reached its daily cap |
| 502 | send_failed | WhatsApp refused or could not be reached (meta_code when WhatsApp gave one) |
| 503 | not_connected, unavailable | Reconnect the number, or retry later |
ChatSa already retries passing WhatsApp failures twice; don't add fast retries on top. Use the same Idempotency-Key when you do retry.
Per-business sending limits#
A business that sends spam has its business-initiated messages (templates and campaigns) paused, while its replies inside the 24-hour window keep working: templates then answer 403 sending_paused with the reasons. New businesses send at most 250 templates a UTC day at first (429 daily_cap_reached, with Retry-After). Neither refusal uses up the Idempotency-Key. See Per-business sending limits and the account.safety event.
Templates#
GET /templates?chatbot_id=&status=all (scope whatsapp:read): approved templates, or every status with status=all. Read from WhatsApp and cached for 5 minutes.
{
"data": {
"templates": [{
"name": "visit_reminder", "language": "en_US", "category": "UTILITY", "status": "APPROVED",
"body": "Hi {{1}}, your visit is at {{2}}.", "body_params": 2,
"header_params": 1, "header_format": "TEXT",
"url_buttons": 1, "url_button_indexes": [1],
"footer": "Reply STOP to opt out",
"buttons": [{ "type": "QUICK_REPLY", "text": "Confirm" }, { "type": "URL", "text": "Details", "url": "https://acmeplumbing.com/v/{{1}}" }],
"quick_reply_indexes": [0]
}]
}
}
POST /templates (scope whatsapp:manage) submits a new template for WhatsApp's review:
{
"chatbot_id": "6f1c…",
"name": "visit_reminder_v2",
"category": "UTILITY",
"language": "en_US",
"header": { "text": "Your visit {{1}}", "example": "tomorrow" },
"body": "Hi {{1}}, your visit with {{2}} is confirmed.",
"examples": ["Jordan", "Acme Plumbing"],
"footer": "Acme Plumbing",
"buttons": [
{ "type": "QUICK_REPLY", "text": "Reschedule" },
{ "type": "URL", "text": "Details", "url": "https://acmeplumbing.com/v/{{1}}", "example": "https://acmeplumbing.com/v/8812" },
{ "type": "PHONE_NUMBER", "text": "Call us", "phone_number": "+14155550123" }
]
}
name: lowercase letters, numbers and underscores.category:MARKETING,UTILITYorAUTHENTICATION.bodyup to 1,024 characters, variables{{1}},{{2}}… in order, with one example each inexamples.headeris optional, text only, at most one variable (with its example).footeris optional, up to 60 characters, no variables.- Up to 10 buttons (at most 2 links and 1 phone number), each text up to 25 characters. A link may end in
{{1}}, which then needs anexample.
201 { "data": { "template": { "id", "name", "language", "status": "PENDING", "category" } } }. WhatsApp's decision arrives as the template.status event. Errors: 400 invalid_request, 409 template_exists, 422 template_rejected (WhatsApp's words in meta_message), 503 not_connected, 502 send_failed.
DELETE /templates?chatbot_id=&name= (scope whatsapp:manage) deletes every language of a template: { "data": { "deleted": true } }. WhatsApp keeps a deleted name unusable for 30 days.
Threads#
GET /threads/{phone}?chatbot_id=&before=&limit= (scope whatsapp:read): every message with one number on this chatbot, in both directions and from every source, newest first (50 by default, 200 at most; pass the previous page's next_before as before).
{
"data": {
"contact": { "phone": "14155550199", "name": "Jordan Lee", "profile_name": "Jordan", "opted_out": false, "window_open_until": "2026-11-30T21:04:00Z", "last_inbound_at": "2026-11-29T21:04:00Z" },
"messages": [{
"id": "b4e1…", "wa_message_id": "wamid.HBgL…", "direction": "out", "type": "text",
"text": "Hi Jordan, your technician arrives at 3 pm.", "template": null, "media": null,
"status": "read", "error": null, "source": "api", "sender": null, "sender_name": "Taylor Brooks",
"reference": { "type": "job", "id": "8812" }, "imported": false, "created_at": "2026-11-30T14:00:00Z"
}],
"next_before": "a71d…"
}
}
source says where a message came from: api, inbox (a reply typed in ChatSa), ai (ChatSa's AI), app (typed in the WhatsApp Business app, with sender: "business_app") or history (imported history, with imported: true). The customer's own messages have source: null; other automatic messages may have null or another value, so treat a value you don't know as automatic.
GET /threads?chatbot_id=&after=&limit= (scope whatsapp:read): the numbers with a message after after (an ISO time; default the last 7 days), newest first (100 by default, 500 at most), to catch up after downtime: { "data": { "threads": [{ "phone", "name", "last_message_at", "last_direction", "last_text" }] } }.
POST /threads/{phone}/read (scope whatsapp:send), body { "chatbot_id", "typing"?: true } (chatbot_id may also be in the query): blue ticks on the customer's latest message. typing: true also shows "typing…" until your next message or 25 seconds. { "data": { "ok": true, "marked": true, "typing": true } }; marked: false when there is nothing to mark.
Taking a conversation over from the AI#
On an AI-mode number, pause ChatSa's AI for one customer while a person answers:
PUT /api/v1/whatsapp/threads/14155550199/control
{ "chatbot_id": "6f1c…", "paused": true, "hours": 12 }
Scope whatsapp:send. chatbot_id is required in the body. hours is 1 to 24 (default 12); "until_resumed": true holds it until you send "paused": false. While paused, the customer's messages are saved and sent to your webhooks, and the AI stays quiet. Answers { "data": { "paused_until": "…" } }: "9999-12-31T00:00:00.000Z" for until resumed, null after "paused": false. 503 save_failed means nothing changed; retry.
Media links#
Media in events and threads is { type, mime_type, filename, caption, size, sha256, url, expires_at, too_large?, voice? }, or null. url is a signed link to ChatSa's private copy, valid 24 hours. GET /media/{message_id}?chatbot_id= (scope whatsapp:read; message_id is ChatSa's id of the message, not wa_message_id) signs a fresh one: { "data": { "url", "expires_at", "type", "mime_type", "filename", "size" } }. It answers 404 not_found when the message has no kept file, and 503 media_unavailable when the link can't be signed right now. Inbound files on Team only numbers, and in conversations you have taken over, are kept (up to 25 MB; larger files keep their details only, with too_large: true and url: null).
Display name#
GET /display-name?chatbot_id= (scope whatsapp:read): display_name, name_status, requested_name, requested_status, official_business_account.
POST /display-name (scope whatsapp:manage; chatbot_id required; name up to 256 characters):
{ "chatbot_id", "action": "request", "name": "Acme Plumbing & Drains" }submits a new name for WhatsApp's review. Sending the same request again while that name is under review or approved changes nothing.{ "chatbot_id", "action": "apply", "name": "…", "pin": "123456" }applies an approved name with the number's six-digit two-step verification PIN. ChatSa never stores the PIN.
Both answer the name's state as GET does; apply adds applied: true. Errors include 422 display_name_pin, 403 display_name_permission, 422 display_name_refused, 409 display_name_pending, display_name_unchanged, display_name_not_approved, display_name_support, 409 not_connected, 429 rate_limited, and 503 display_name_unavailable (refresh the status before trying again).
Voice notes and trained voices#
GET /voice?chatbot_id=&owner_ref= (scope whatsapp:read; owner_ref, your own id for the person, is required): { "data": { "configured", "allowed", "enabled", "voices": [{ "id", "name", "is_default" }], "consent_text" } }. allowed says whether the plan includes voice, enabled whether automatic voice replies are on, and voices lists the trained voices owned by owner_ref.
POST /voice (Idempotency-Key header required, up to 100 characters; scope whatsapp:voice, and whatsapp:manage for settings and default). Every body has chatbot_id, owner_ref and an action:
prepare: a recording (audioin base64, withmime_typeandseconds) becomes a voice-note preview.speak:text(up to 1,200 characters) becomes a preview, in the trained voicevoice_idor the chatbot's reply voice.clone: trains a voice fromaudioof 10 to 300seconds, with anameandconsent: true(the person acceptsconsent_text). Answers{ "data": { "voice": { "id", "name", "is_default" } } }.deleteanddefaulttake avoice_id;defaultmakes it the voice the AI replies in.settings:enabledturns automatic voice replies on or off.
A preview answers { "data": { "media", "transcript" } }, with media as in Media links. It is never sent by itself: send it with POST /messages. A plan without voice answers 403 feature_locked; a body over about 3.7 MB answers 413 too_large. Each workspace may generate 100,000 characters of speech and train 20 voices a calendar month (UTC); past that, 429 voice_allowance_exhausted. The same Idempotency-Key within 24 hours answers the first result again, refusals included; only 409, 429 and 5xx answers free the key.
Rate limits#
Per key: 60 sends (and other writes) and 600 reads a minute. Past them: 429 rate_limited with Retry-After.