Skip to content
WhatSync/DocsAPI v1

WhatsApp events on your server

Register a URL and receive signed events from the WhatsApp chats your settings show.

Add your endpoint

Open Developers, add a public HTTPS URL, choose events and copy the signing secret. The dashboard queues a test event and displays its delivery result. Your receiver should verify the signature, durably accept the event, and return 2xx quickly. Do longer work in your own queue. API keys with whatsapp.webhooks:manage can also register and manage endpoints.

Code
curl -X POST https://whatsync.app/api/v1/webhooks \
  -H "Authorization: Bearer $WHATSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"url":"https://your-server.example/whatsync","event_types":["message.received"]}'

Receivers that need their own key

Some receivers refuse any request without their own key, such as a Cursor automation, which answers 401 "Missing Authorization header". Add up to five headers to the webhook and every delivery carries them. Values are stored encrypted and never shown again; the API returns header_names only. On PATCH, headers replaces the whole set and null removes it. WhatSync's own headers (Content-Type, User-Agent, Webhook-*) cannot be changed. You can also add headers in Developers when you add or edit a webhook.

Code
curl -X PATCH https://whatsync.app/api/v1/webhooks/we_... \
  -H "Authorization: Bearer $WHATSYNC_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"headers":{"Authorization":"Bearer YOUR_CURSOR_KEY"}}'

Only saved chats produce message events

The same people filters and group settings that decide what your AI sees also decide which chats send events. Groups are on by default; an unticked group sends no events. Your own replies produce message.sent, never message.received. QR delivery ticks are not available in version one; message.status is Business only. poll.vote_updated covers polls on a linked personal WhatsApp (QR) that were saved in a saved chat: each event is one person's whole current choice after they vote, change their vote or remove it (selected_options is empty and retracted is true). It is not a running total. Keep the newest vote.voted_at per poll.id and vote.voter.jid; voted_at is null if WhatsApp supplied no timestamp, so do not treat an undated event as newer. Votes on a poll sent before the chat was saved cannot be read. voter.jid can be a WhatsApp LID; voter.phone is null unless WhatsApp shared the real number. Short QR reconnects do not produce disconnection alerts; states requiring human action do.

Several numbers

Every event carries whatsapp_number: the id, phone and name of the account's number it belongs to. To reply from the same number, pass whatsapp_number.phone as fromNumber. account_id equals whatsapp_number.id. GET /api/v1/me lists every number in numbers, with its id, phone, name, how it is linked (qr, business or both) and whether it is connected. A Business number going away sends connection.disconnected with reason disconnected_by_user (disconnected in WhatSync), connected_elsewhere (connected again somewhere else), meta_disconnected (WhatSync removed in Meta Business Settings, or the account deleted or disabled by Meta) or meta_token_invalid (Meta stopped accepting WhatSync's access). On an account with several numbers, dashboard_url in connection.disconnected opens that number with its linking started (/dashboard?number=<id>&connect=qr); with one number it is the plain dashboard link.

Events and payloads

message.received
Code
{
  "id": "evt_01J9XK2Q8V7Y3M4N5P6R7S8T9U",
  "type": "message.received",
  "created_at": "2026-10-08T09:41:12.512Z",
  "api_version": "2026-10-01",
  "account_id": "conn_example",
  "data": {
    "message": {
      "id": "example-message",
      "stored_message_id": "conn_example_example-message",
      "conversation_id": "120363012345678901@g.us",
      "channel": "qr",
      "chat_type": "group",
      "group": {
        "id": "120363012345678901@g.us",
        "name": "Site requests"
      },
      "from": {
        "phone": "15550000001",
        "name": "Ravi"
      },
      "from_me": false,
      "type": "text",
      "text": "Need 20 bags of cement at block C",
      "quoted_message_id": null,
      "has_attachment": false,
      "attachment": null,
      "timestamp": "2026-10-08T09:41:11.000Z"
    }
  },
  "whatsapp_number": {
    "id": "conn_example",
    "phone": "+15550000002",
    "name": "Sample account"
  }
}
message.sent
Code
{
  "id": "evt_01J9XK2Q8V7Y3M4N5P6R7S8T9U",
  "type": "message.sent",
  "created_at": "2026-10-08T09:41:12.512Z",
  "api_version": "2026-10-01",
  "account_id": "conn_example",
  "data": {
    "message": {
      "id": "example-message",
      "stored_message_id": "conn_example_example-message",
      "conversation_id": "120363012345678901@g.us",
      "channel": "qr",
      "chat_type": "group",
      "group": {
        "id": "120363012345678901@g.us",
        "name": "Site requests"
      },
      "from": {
        "phone": "15550000001",
        "name": "Ravi"
      },
      "from_me": true,
      "type": "text",
      "text": "Need 20 bags of cement at block C",
      "quoted_message_id": null,
      "has_attachment": false,
      "attachment": null,
      "timestamp": "2026-10-08T09:41:11.000Z"
    }
  },
  "whatsapp_number": {
    "id": "conn_example",
    "phone": "+15550000002",
    "name": "Sample account"
  }
}
message.status
Code
{
  "id": "evt_01J9XK2Q8V7Y3M4N5P6R7S8T9U",
  "type": "message.status",
  "created_at": "2026-10-08T09:41:12.512Z",
  "api_version": "2026-10-01",
  "account_id": "conn_example",
  "data": {
    "message_id": "wamid.example",
    "conversation_id": "15550000001",
    "channel": "business",
    "status": "delivered",
    "errors": [],
    "timestamp": "2026-10-08T09:41:12.000Z"
  },
  "whatsapp_number": {
    "id": "conn_example",
    "phone": "+15550000002",
    "name": "Sample account"
  }
}
connection.connected
Code
{
  "id": "evt_01J9XK2Q8V7Y3M4N5P6R7S8T9U",
  "type": "connection.connected",
  "created_at": "2026-10-08T09:41:12.512Z",
  "api_version": "2026-10-01",
  "account_id": "conn_example",
  "data": {
    "channel": "qr",
    "phone": "15550000001"
  },
  "whatsapp_number": {
    "id": "conn_example",
    "phone": "+15550000001",
    "name": "Sample account"
  }
}
connection.disconnected
Code
{
  "id": "evt_01J9XK2Q8V7Y3M4N5P6R7S8T9U",
  "type": "connection.disconnected",
  "created_at": "2026-10-08T09:41:12.512Z",
  "api_version": "2026-10-01",
  "account_id": "conn_example",
  "data": {
    "channel": "qr",
    "phone": "15550000001",
    "reason": "logged_out",
    "action_needed": "scan_qr",
    "dashboard_url": "https://whatsync.app/dashboard"
  },
  "whatsapp_number": {
    "id": "conn_example",
    "phone": "+15550000001",
    "name": "Sample account"
  }
}
poll.vote_updated
Code
{
  "id": "evt_01J9XK2Q8V7Y3M4N5P6R7S8T9U",
  "type": "poll.vote_updated",
  "created_at": "2026-10-08T09:41:12.512Z",
  "api_version": "2026-10-01",
  "account_id": "conn_example",
  "data": {
    "poll": {
      "id": "3EB0C0A1B2C3D4E5F6A7",
      "stored_message_id": "conn_example_3EB0C0A1B2C3D4E5F6A7",
      "conversation_id": "120363012345678901@g.us",
      "channel": "qr",
      "chat_type": "group",
      "group": {
        "id": "120363012345678901@g.us",
        "name": "Saturday event"
      },
      "name": "Which slot works?",
      "options": [
        "10am",
        "4pm",
        "Can't come"
      ],
      "selectable_count": 1
    },
    "vote": {
      "id": "3EB0F1E2D3C4B5A69788",
      "voter": {
        "jid": "15550000001@s.whatsapp.net",
        "phone": "15550000001",
        "name": "Ravi"
      },
      "from_me": false,
      "selected_options": [
        {
          "index": 1,
          "name": "4pm"
        }
      ],
      "retracted": false,
      "voted_at": "2026-10-08T09:41:11.123Z"
    }
  },
  "whatsapp_number": {
    "id": "conn_example",
    "phone": "+15550000002",
    "name": "Sample account"
  }
}
webhook.test
Code
{
  "id": "evt_01J9XK2Q8V7Y3M4N5P6R7S8T9U",
  "type": "webhook.test",
  "created_at": "2026-10-08T09:41:12.512Z",
  "api_version": "2026-10-01",
  "account_id": "conn_example",
  "data": {
    "message": "This is a WhatSync webhook test."
  },
  "whatsapp_number": {
    "id": "conn_example",
    "phone": "+15550000002",
    "name": "Sample account"
  }
}

conversation_id can be passed to the matching send or read tool. Attachments contain metadata; call get_attachment_link with stored_message_id once the file has been saved to obtain a current download link. A file sent to a Business number is fetched from Meta a few moments after it arrives; until then get_attachment_link says it is not saved yet. A Business message from someone who tapped a click-to-WhatsApp ad or post carries ad_referral (headline, source_url, source_id, source_type, body, media_type, ctwa_clid). Photos and videos sent together as one album each carry album: { id, expected_images, expected_videos }, with the same id for every item of the album. The album message itself also arrives, as type album with no text, and its stored_message_id is that id. expected_images and expected_videos are null when not known: some phones don't give them, and a photo can arrive before its album message, so don't wait for a count that may not come. Payloads are capped at 256 KB; oversized text includes text_truncated=true. All event times are UTC. Each endpoint stays on its payload API version; ignore unknown fields.

Verify the original request body

Signing follows Standard Webhooks. Verify webhook-id, webhook-timestamp and webhook-signature using your endpoint secret. Reject timestamps more than five minutes from your clock. Do this before parsing JSON. Rotating a secret sends both signatures for 24 hours.

Node.js
Code
import { createHmac, timingSafeEqual } from 'node:crypto';
export function verify(body, headers, secret) {
  const id = headers['webhook-id'];
  const ts = headers['webhook-timestamp'];
  if (!id || !/^\d+$/.test(ts || '') || Math.abs(Date.now()/1000 - Number(ts)) > 300) throw new Error('Stale webhook');
  const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
  const expected = createHmac('sha256', key).update(id + '.' + ts + '.').update(body).digest();
  const valid = (headers['webhook-signature'] || '').split(' ').some(value => {
    const [version, encoded] = value.split(',');
    const actual = Buffer.from(encoded || '', 'base64');
    return version === 'v1' && actual.length === expected.length && timingSafeEqual(actual, expected);
  });
  if (!valid) throw new Error('Invalid signature');
  return JSON.parse(body.toString('utf8'));
}
// body must be the original raw bytes, before JSON parsing.
Python
Code
import base64, hashlib, hmac, json, time
def verify(body, headers, secret):
    event_id = headers.get('webhook-id', '')
    ts = headers.get('webhook-timestamp', '')
    if not event_id or not ts.isdigit() or abs(time.time() - int(ts)) > 300:
        raise ValueError('Stale webhook')
    key = base64.b64decode(secret.removeprefix('whsec_'))
    expected = base64.b64encode(hmac.new(key, (event_id + '.' + ts + '.').encode() + body, hashlib.sha256).digest()).decode()
    valid = any(s.startswith('v1,') and hmac.compare_digest(s[3:], expected) for s in headers.get('webhook-signature', '').split(' '))
    if not valid:
        raise ValueError('Invalid signature')
    return json.loads(body)
# body is bytes from the request; normalize header names to lowercase.
PHP
Code
function verify_webhook($body, $headers, $secret) {
    $id = $headers['webhook-id'] ?? '';
    $ts = $headers['webhook-timestamp'] ?? '';
    if (!$id || !ctype_digit($ts) || abs(time() - (int)$ts) > 300) throw new Exception('Stale webhook');
    $key = base64_decode(preg_replace('/^whsec_/', '', $secret), true);
    if ($key === false) throw new Exception('Invalid secret');
    $expected = base64_encode(hash_hmac('sha256', $id.'.'.$ts.'.'.$body, $key, true));
    $valid = false;
    foreach (explode(' ', $headers['webhook-signature'] ?? '') as $signature) {
        if (str_starts_with($signature, 'v1,') && hash_equals($expected, substr($signature, 3))) $valid = true;
    }
    if (!$valid) throw new Exception('Invalid signature');
    return json_decode($body, true, 512, JSON_THROW_ON_ERROR);
}
// $body = file_get_contents('php://input'); lowercase the header names.

Delivery, retries and retention

Queued events are delivered at least once; duplicates are possible and order is not guaranteed. Deduplicate the stable event ID and use event/message timestamps to interpret ordering. Failures retry after 30 seconds, 2 minutes, 10 minutes, 30 minutes, 1 hour, 3 hours, 6 hours and 12 hours, with ±20% jitter. After nine attempts the delivery fails. HTTP 410 disables an endpoint immediately. An endpoint with 100 consecutive failures and no success for three days is disabled. No redirects are followed and requests time out after ten seconds.

Payloads and response excerpts are retained for seven days; delivery metadata lasts thirty days. Resend is available while the payload exists. Paused or deleted endpoints stop future requests; a request already in flight may finish. Saving a message and queueing its event are separate operations: a failure between them can miss an event, and a later duplicate message can repair that gap. This service does not promise every WhatsApp event will be captured.

MCP events: wake an AI app when a message arrives

The MCP server at https://whatsync.app/api/mcp also speaks MCP Events as ChatGPT implements them: initialize returns capabilities.events, and events/list, events/subscribe and events/unsubscribe sit on the same signed-in endpoint as the tools. Delivery is webhook only. Two events: message.received (filters conversationId, phoneNumber, chatType direct by default, keywords, mentionsMe, newPeopleOnly, messageTypes, number) and connection.disconnected (number). A notice carries ids and who wrote, never message text: read it with get_message_context or get_conversation. API keys use the webhooks above instead.

Code
{"eventId":"evt_01JD...","name":"message.received","timestamp":"2026-11-21T09:14:03.120Z","cursor":null,
 "data":{"messageId":"conn_abc_3EB0...","conversationId":"919876543210@s.whatsapp.net","chatType":"direct",
  "chatName":"Priya Sharma","group":null,"from":{"phone":"+919876543210","name":"Priya Sharma"},"toNumber":"+971501234567",
  "messageType":"text","hasAttachment":false,"mentionsMe":false,"firstMessageInChat":null,"sentAt":"2026-11-21T09:14:01.000Z","moreSinceLastEvent":0}}

Subscribing checks the plan (10 on Plus, Pro and Max, 25 on Business, one on the free trial; an ended trial or plan is refused with -32024 and a message saying so), the account's watch limit, and the callback: a signed POST of {"type":"verification","challenge":"..."} must come back 2xx with the same challenge within ten seconds, or the call fails with -32015 and data.reason challenge_failed, timeout, unreachable or blocked_address. The same request again is a renewal with the same sub_ id. Lifetimes run from one hour to seven days (72 hours by default); refreshBefore is ten percent before the end. Each notice is signed with Standard Webhooks using the callback's secret, webhook-id equals eventId and X-MCP-Subscription-Id names the watch. Retries come after 30 seconds, 2, 5, 15 and 30 minutes and 1 hour; 410 ends the watch and 413 is not retried. A watch sends at most one notice a minute and ten an hour per chat and sixty an hour in all; messages in between are counted in moreSinceLastEvent. Access is checked again before each notice: removing the AI app, unlinking WhatsApp or an ended plan ends the watch. With several numbers, unlinking one ends only the watches that name it; a watch with no number keeps covering the others.