← Home · Docs

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

  1. Sign in to the workspace as the owner or director and open Settings → API and webhooks.
  2. Issue an API key. It’s shown only once: save it in your server’s secrets right away.
  3. 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.
  4. 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":[]}}'

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"
    }
  ]
}

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…"
}

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.

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

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 }.

How to link identifiers

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

Support

API questions: hello@wtsp.cloud or WhatsApp +7 706 656 48 16.