API and webhooks
The API sends messages from the WhatsApp numbers of your Wtsp Cloud workspace, and the webhook notifies your system about everything that happens in conversations. Available on the «Business» and «PRO» plans. The number is connected in the workspace through the Meta window, and the workspace is identified by the key, so you don’t need to pass the WABA ID or phone number ID.
Setup
- Sign in to the workspace as the owner or director and open Settings → API and webhooks.
- Issue an API key. It’s shown only once: save it in your server’s secrets right away.
- Enter the HTTPS webhook URL. The signing secret is created automatically and is also shown only once. Lost it? Issue a new one on the same page.
- Write to the connected number and check that the event arrived and the signature matched.
Keep the key and secret on the server only. Don’t put them in page code or send them in chats and emails.
Authorization
Authorization: Bearer <ваш ключ API> Idempotency-Key: <uuid> # обязателен для POST Content-Type: application/json
Send a message
POST https://wtsp.cloud/api/v1/messages returns 202 { "id": "msg_…", "status": "queued" }.
curl -X POST https://wtsp.cloud/api/v1/messages \
-H "Authorization: Bearer $WTSP_KEY" \
-H "Idempotency-Key: $(uuidgen)" \
-H "Content-Type: application/json" \
-d '{"to":"77011234567","type":"template",
"template":{"name":"order_update","language":{"code":"ru"},"components":[]}}'type: "text"with"text": { "body": "…" }: only within the 24-hour window after the customer’s message (a Meta rule).type: "template": a Meta-approved template. Templates are created in the workspace, in «Broadcasts».from(optional): the workspace number in digits, if there are several. Without it, the number of the last conversation with the customer or the primary number is used.- One recipient per request. The same Idempotency-Key with the same body returns the same response.
- Limit: 60 requests per minute per workspace; beyond that, 429 with Retry-After.
Message status
GET https://wtsp.cloud/api/v1/messages/:id returns the status queued | submitted | sent | delivered | read | failed | unknown and the provider_message_id field with the wamid.
Workspace numbers
GET https://wtsp.cloud/api/v1/connections returns all connected numbers of the workspace, including disconnected ones. Use connection_id and phone_number_id from the webhook to find the number and its name.
{
"data": [
{
"connection_id": "uuid",
"waba_id": "123",
"phone_number_id": "456",
"phone": "77715255247",
"name": "Актау",
"status": "active",
"mode": "cloud_api",
"created_at": "2026-11-11T10:20:00.000Z",
"updated_at": "2026-11-12T06:00:00.000Z"
}
]
}phone: digits in international format, likemessage.toin the inbound webhook.name: the number’s name in the workspace,nullif not set.status:activemeans working,action_requiredmeans action is needed in the workspace,disconnectedmeans disconnected.mode:coexistence(the number is also in the WhatsApp Business app) orcloud_api.
Conversation history with a customer
GET https://wtsp.cloud/api/v1/messages?phone=%2B77011234567&limit=50 returns messages from all of the workspace’s conversations with this number, newest first. For the next page, pass &before= with the next_cursor value from the response; null means there are no more pages.
{
"data": [
{
"id": "msg_…",
"wamid": "wamid.…",
"direction": "outbound",
"type": "text",
"text": "Добрый день",
"status": "read",
"created_at": "2026-11-10T09:00:00.000Z",
"connection_id": "uuid",
"sender": { "source": "bitrix24", "name": "Имя сотрудника" }
}
],
"next_cursor": "MjAyNi0xMS0xMCAw…"
}phone: in international format; write the+sign in the URL as%2Bor pass digits only.limit: from 1 to 100, 50 by default.text: the message text, file caption or template text;nullif there is no text.statusandsenderexist only on outbound messages.- History requests count toward the same 60-per-minute limit as sending.
Webhook: which events arrive
One URL per workspace; it receives all events for all numbers. You can’t select individual events: just ignore the ones you don’t need and respond with 2xx. Identify the number by connection_id or channel.phone_number_id.
whatsapp.message.inbound: a customer message: text, button, interactive reply.whatsapp.message.unsupported: photo, voice message, video, document, sticker, location, contact and other types. Handle it together with inbound, otherwise these messages will be lost.whatsapp.message.outbound: a message was sent from the platform: workspace, Bitrix24, amoCRM, API, broadcast, bots. Includes the source and author.whatsapp.message.echo: a message was sent from the WhatsApp Business app on the phone.whatsapp.message.status: outbound message status: sent, delivered, read, failed.whatsapp.connection.state_changed: the state of the number or account changed.
Signature
X-WabaKz-Event: whatsapp.message.status X-WabaKz-Event-Id: evt_… X-WabaKz-Delivery-Id: … X-WabaKz-Timestamp: 1720000000 X-WabaKz-Signature: v1=<hmac в hex>
The signature is HMAC-SHA256 in hex of the string timestamp.rawBody, where rawBody is the request body byte for byte, before JSON parsing. The timestamp is in seconds and new on every attempt. We recommend rejecting requests older than 5 minutes.
import { createHmac, timingSafeEqual } from 'node:crypto';
function isValid(rawBody, timestamp, signature, secret) {
const age = Math.abs(Date.now() / 1000 - Number(timestamp));
if (!(age <= 300)) return false;
const digest = createHmac('sha256', secret)
.update(timestamp + '.' + rawBody)
.digest('hex');
const expected = Buffer.from('v1=' + digest);
const received = Buffer.from(signature);
return expected.length === received.length && timingSafeEqual(expected, received);
}Delivery and retries
- Respond with 2xx within 10 seconds. Do heavy processing after responding.
- On a network failure, timeout or 5xx response, we retry after 1 min, 5 min, 15 min, 1 h and 6 h, after which the event is considered undelivered.
- No retry on a 4xx response or a redirect.
- An event may arrive twice; deduplicate by
X-WabaKz-Event-Id. - Order isn’t guaranteed: a status may arrive before the outbound event.
Replay missed events
If your server was unavailable and events didn’t get through after all retries, request them again:
curl -X POST https://wtsp.cloud/api/v1/webhooks/replay \
-H "Authorization: Bearer $WTSP_KEY" \
-H "Content-Type: application/json" \
-d '{"since":"2026-11-09T00:00:00Z","until":"2026-11-10T00:00:00Z"}'Response 202 { "queued": 120, "truncated": false }.
since: required, a time with a time zone, no older than 90 days.until: now by default. The window is at most 7 days."status": "dead"(default): only events undelivered after all retries;"status": "all": delivered ones too. Events currently waiting for a retry aren’t sent a second time.- Up to 1000 events per call, earliest first.
truncated: truemeans there are more in the window: fordeadrepeat the same request, forallmovesinceforward. - Events arrive with the same
X-WabaKz-Event-Id, so duplicates are filtered as usual. The webhook must be enabled, otherwise 409. No more than 3 requests per minute.
How to link identifiers
message.idandstatus.message_idare the wamid; it is the same in all events of one message.- REST returns
msg_…. The outbound event contains both values:message.idandmessage.api_id.
Who sent it
In the outbound event, the message.sender.source field takes the values cabinet | bitrix24 | amocrm | api | campaign | ai_bot | chatbot | system. The message.sender.name field contains the employee’s name when it’s known; otherwise it’s absent or null. A message from the app on the phone arrives as an echo event, and the employee’s name isn’t passed there.
message.sender.id is the author’s permanent id in the system the message was sent from: for cabinet it’s the Wtsp Cloud user id, for bitrix24 the portal employee ID, for amocrm the amoCRM user id. If the author is unknown (a robot, a rule), the field is null. message.sender.is_automated is true when the message was sent without a person: a broadcast, AI bot, chatbot, system message, Bitrix24 robot, or an amoCRM rule or Salesbot.
Meta ads
For the first message after an ad click, message.referral contains source_type, source_id, source_url, headline, body and ctwa_clid. For other messages it is null.
Event examples
Values are illustrative. All events contain id, type, occurred_at, tenant_id, connection_id and channel. In the following examples these fields are omitted.
whatsapp.message.inbound
{
"id": "evt_…",
"type": "whatsapp.message.inbound",
"occurred_at": "2026-11-06T10:00:00.000Z",
"tenant_id": "uuid",
"connection_id": "uuid",
"channel": {
"provider": "meta_cloud",
"waba_id": "123",
"phone_number_id": "456",
"mode": "coexistence"
},
"message": {
"id": "wamid.…",
"direction": "inbound",
"origin": "customer",
"from": "77011234567",
"to": "77021234567",
"type": "text",
"text": { "body": "Здравствуйте" },
"media": null,
"context_message_id": null,
"reaction": null,
"referral": null
},
"contact": { "wa_id": "77011234567", "profile_name": "Имя" }
}whatsapp.message.unsupported
The file caption arrives in text. The file itself can’t be downloaded via the API yet.
{
"type": "whatsapp.message.unsupported",
"message": {
"id": "wamid.…",
"direction": "inbound",
"origin": "customer",
"from": "77011234567",
"to": "77021234567",
"type": "image",
"text": { "body": "Подпись к фото" },
"media": { "id": "1234567890", "mime_type": "image/jpeg", "filename": null }
},
"contact": { "wa_id": "77011234567", "profile_name": "Имя" }
}whatsapp.message.outbound
For a template, template contains the name and language, and text contains its text. For a file, the type and caption arrive.
{
"type": "whatsapp.message.outbound",
"message": {
"id": "wamid.…",
"api_id": "msg_…",
"direction": "outbound",
"origin": "business",
"from": "77021234567",
"to": "77011234567",
"type": "text",
"text": { "body": "Добрый день" },
"media": null,
"context_message_id": null,
"sender": { "source": "bitrix24", "name": "Имя сотрудника", "id": "17", "is_automated": false },
"template": null
},
"contact": { "wa_id": "77011234567", "profile_name": null }
}whatsapp.message.echo
{
"type": "whatsapp.message.echo",
"message": {
"id": "wamid.…",
"direction": "outbound",
"origin": "business",
"from": "77021234567",
"to": "77011234567",
"type": "text",
"text": { "body": "Добрый день" }
}
}whatsapp.message.status
{
"type": "whatsapp.message.status",
"status": {
"message_id": "wamid.…",
"status": "delivered",
"recipient": "77011234567",
"error_code": null
}
}whatsapp.connection.state_changed
state is the Meta field name. The event, effect and summary fields may be missing. effect: blocked | restricted | restored.
{
"type": "whatsapp.connection.state_changed",
"connection": {
"state": "account_update",
"event": "DISABLED_UPDATE",
"effect": "blocked",
"summary": "Описание изменения"
}
}Errors
{ "error": { "code": "…", "message": "…", "request_id": "req_…" } }: 401 invalid key, 403 plan, 400 invalid request or unknown template, 409 number not connected, 429 limit.
What the API doesn’t have yet
- Downloading files from messages.
- CRM data: deals, pipelines and assignees.
Support
API questions: hello@wtsp.cloud or WhatsApp +7 706 656 48 16.