Build on WhatsApp with an API you can trust
Send messages, sync contacts and react to events from your own software. Scoped keys, safe retries, signed and timestamped webhooks, and a spec that always matches the server.
- Bearer API keys with scopes
- JSON over HTTPS
- HMAC-signed webhooks
- OpenAPI 3.1 spec
Quickstart
From zero to your first message in three steps.
Create an API key
In the app, open Settings, then Developers, and create a key with only the scopes you need. The full key is shown once, so store it as a secret on your server.
Make your first request
Call GET /me to confirm the key works, then send a template message. Sending needs an Idempotency-Key so a retry can never message the customer twice.
Listen for events
Add a webhook endpoint, pick the events, and verify the signature on every request. You get message status, replies, contact and template changes as they happen.
The REST API is included in the Pro and Business plans.
Check the connection
curl https://24msg.com/api/v1/me \
-H "Authorization: Bearer $API_KEY"Send a template message
curl https://24msg.com/api/v1/messages \
-H "Authorization: Bearer $API_KEY" \
-H "Idempotency-Key: order-1042-confirmation" \
-H "Content-Type: application/json" \
-d '{
"to": { "phone": "+14155550123" },
"type": "template",
"template": {
"name": "order_confirmation",
"language": "en",
"variables": { "1": "Alex", "2": "SO-1042" }
}
}'{
"id": "0197d3a4-1b2c-7d00-8e11-2f3a4b5c6d7e",
"conversationId": "0197d3a4-1b2c-7d00-8e11-2f3a4b5c6d7f",
"contactId": "0197d3a4-1b2c-7d00-8e11-2f3a4b5c6d80",
"channelId": "0197d3a4-1b2c-7d00-8e11-2f3a4b5c6d81",
"status": "queued",
"createdAt": "2026-11-17T10:00:00.000Z"
}Built so integrations do not break at 2 a.m.
Four details that save you from the usual webhook and retry headaches.
Signed and timestamped webhooks
Each delivery has an HMAC-SHA256 signature over the timestamp and the exact body. Replays older than five minutes are rejected, and a rotated secret stays valid for 24 hours so you can switch without downtime.
Idempotency-Key on every write
Retry a POST after a timeout without doing the work twice. The same key with the same body returns the first response. For sending messages the header is required.
A documented retry policy
Seven attempts over about 32 hours on a fixed schedule, a log of every attempt you can resend from, and an automatic pause with an email when an endpoint keeps failing. No guessing.
OpenAPI 3.1 that cannot drift
The spec is generated from the same schemas the server validates requests against. Import it into Postman or Insomnia, or generate a typed client in your language.
Authentication and scopes
Send your key as a Bearer token. Keys belong to one workspace and carry only the scopes you picked.
Authorization: Bearer 24msg_live_a41f09c2_<64 hex characters>Keys are server-side secrets. The API has no CORS, so never put a key in a browser or mobile app. A missing scope returns 403 with the scope that is required.
Scopes
| Scope | Allows |
|---|---|
| contacts:read | Read contacts, tags and attributes. |
| contacts:write | Create and update contacts and their attributes. |
| consents:write | Record opt-in and opt-out evidence for a contact. |
| tags:write | Add and remove tags on contacts. |
| conversations:read | List conversations and their status. |
| messages:read | Read message content and delivery status. |
| messages:send | Send text, media and template messages. |
| templates:read | List approved message templates. |
| channels:read | List connected WhatsApp numbers. |
| events:write | Push commerce events (orders, carts) to trigger automations. |
| webhooks:manage | Create and manage webhook endpoints through the API. |
Scopes are chosen when the key is created and cannot change. To change them, create a new key and revoke the old one.
Limits by plan
| Plan | Active keys | Requests per minute |
|---|---|---|
| Pro | 3 | 60 |
| Business | 10 | 300 |
The rate limit is shared by all keys in a workspace, so opening more keys does not raise it.
Errors, paging and rate limits
The same predictable shapes everywhere, so one client handles every endpoint.
Error envelope
Every error has the same JSON shape. Quote requestId when you contact support. details.reason gives a machine-readable cause.
{
"code": "validation",
"message": "Idempotency-Key header is required",
"requestId": "req_8f3a1c2e",
"details": { "reason": "idempotency_key_required" }
}| Status | code | Meaning |
|---|---|---|
| 400 | validation | The body or query is invalid. See details.issues. |
| 401 | unauthenticated | The key is missing, malformed, revoked or expired. |
| 402 | limit_reached | A plan limit was reached (keys, endpoints, contacts). |
| 403 | forbidden · feature_locked | A scope is missing, or the plan has no REST API. |
| 404 | not_found | Not found. Resources of other workspaces are also 404. |
| 409 | conflict | Conflict, for example an idempotent request still in progress. |
| 422 | validation · no_consent · template_required | A business rule blocked it: window closed, no consent, template not approved, or an Idempotency-Key reused with a different body. |
| 429 | rate_limited | Rate limit exceeded. Wait Retry-After seconds. |
| 500 | internal | Our side. Retry with backoff and quote requestId. |
Pagination
List endpoints return newest first as { data, nextCursor }. Pass nextCursor back as ?cursor= until it is null. limit is 1 to 100 and defaults to 25. There is no total count.
Idempotency
Send Idempotency-Key with any POST. Keys are scoped to your workspace and kept for 24 hours. Same key and same body returns the original response with Idempotent-Replayed: true. Same key with a different body returns 422. POST /messages requires the header.
Rate limit headers
Every response, errors included, tells you where you stand. On 429, wait for Retry-After seconds. The window is 60 seconds, so a burst at the boundary can reach twice the limit.
| Header | Value |
|---|---|
| X-RateLimit-Limit | Requests allowed per window |
| X-RateLimit-Remaining | Requests left in this window |
| X-RateLimit-Reset | When the window resets (Unix seconds) |
| Retry-After | 429 |
Webhooks
We POST JSON to your HTTPS endpoint when something happens. Verify the signature, answer 2xx quickly, and do the heavy work in a queue.
The event envelope
Every event has the same outer shape. id is the event ID and stays the same on every retry and resend, so use it to deduplicate. Unknown fields may appear later: ignore them.
{
"id": "0197d3a2-7c1e-7a10-9a3f-5b2c8e1d4f60",
"type": "message.received",
"apiVersion": "1",
"occurredAt": "2026-11-17T10:00:00.000Z",
"workspaceId": "0197d3a2-0000-7000-8000-00000000a001",
"data": {
"message": { "id": "…", "direction": "in", "type": "text", "status": "delivered" },
"contact": { "id": "…", "phone": "+14155550123", "externalId": null, "name": "Alex" }
}
}Request headers
| Header | Value |
|---|---|
| X-24msg-Signature | Timestamp and signature, see below |
| X-24msg-Event-Id | Event ID: your deduplication key |
| X-24msg-Event-Type | The event type, for example message.received |
| X-24msg-Delivery-Id | ID of this delivery |
| X-24msg-Delivery-Attempt | Attempt number, 1 to 7 |
Verify the signature
The signature is an HMAC-SHA256 of the timestamp, a dot and the raw request body, keyed with your whsec_ secret.
- Read the X-24msg-Signature header: t=1763380800,v1=5257a8…. There can be two v1 values during a secret rotation.
- Reject the request if the timestamp differs from your clock by more than 300 seconds.
- Compute HMAC-SHA256 over t + "." + the raw body, using the whole whsec_ string as the key.
- Compare with every v1 value in constant time. Any match is valid.
- Answer 2xx fast and store the event ID for at least 7 days, so a resend is ignored.
Use the raw body bytes exactly as received. If your framework parses JSON first and you re-serialize it, the signature will not match.
import crypto from "node:crypto";
import express from "express";
export function verifySignature(rawBody, header, secret, toleranceSec = 300) {
let t = "";
const signatures = [];
for (const part of header.split(",")) {
const [key, value] = part.trim().split("=");
if (key === "t") t = value;
if (key === "v1") signatures.push(value);
}
if (!/^\d+$/.test(t) || Math.abs(Date.now() / 1000 - Number(t)) > toleranceSec) return false;
const expected = crypto
.createHmac("sha256", secret) // the whole whsec_... string
.update(`${t}.`)
.update(rawBody) // Buffer: the bytes exactly as received
.digest();
return signatures.some((sig) => {
const got = Buffer.from(sig, "hex");
return got.length === expected.length && crypto.timingSafeEqual(got, expected);
});
}
const app = express();
app.post("/hooks/24msg", express.raw({ type: "application/json" }), (req, res) => {
const ok = verifySignature(req.body, req.get("X-24msg-Signature") ?? "", process.env.WHSEC);
if (!ok) return res.sendStatus(400);
const event = JSON.parse(req.body); // dedupe on event.id, then enqueue
res.sendStatus(200);
});Retry policy
A delivery succeeds on any 2xx within 10 seconds. Redirects are not followed and count as failures. We try up to seven times on this schedule, with about 10 percent jitter, then mark the delivery failed. You can resend it from the delivery log or the API with the same event ID.
| Attempt | Sent |
|---|---|
| 1 | Immediately |
| 2 | 1 minute after the failure |
| 3 | 5 minutes later |
| 4 | 30 minutes later |
| 5 | 2 hours later |
| 6 | 6 hours later |
| 7 | 24 hours later, then marked failed |
Automatic pause
If an endpoint fails 50 deliveries in a row over at least 24 hours, we pause it and email the workspace owners and admins. Fix it, re-enable it in the app, and resend what you missed.
Delivery guarantees
Delivery is at least once and not ordered. An event can arrive twice, or after a later one: deduplicate by event ID and sort by occurredAt.
Where we send
Endpoints must be public HTTPS addresses on port 443. We refuse private and internal addresses, and check again on every attempt.
Event catalog
Subscribe to the events you need, or to all of them. The data column shows what goes in data.
Messages
| Event | When it fires | data |
|---|---|---|
| message.received | A customer message arrived. | message, contact |
| message.sent | An outgoing message was accepted by WhatsApp. | message |
| message.delivered | An outgoing message reached the phone. | message |
| message.read | The customer read the message. | message |
| message.failed | A message could not be delivered. | message (error) |
Conversations
| Event | When it fires | data |
|---|---|---|
| conversation.opened | A new conversation started or was reopened. | conversation |
| conversation.assigned | A conversation was assigned or unassigned. | conversationId, assigneeMemberId, previousAssigneeMemberId |
| conversation.closed | A conversation was resolved. | conversationId, closedAt |
Contacts
| Event | When it fires | data |
|---|---|---|
| contact.created | A new contact was created. | contact |
| contact.updated | A contact changed. | contact, changedFields |
| contact.consent_changed | A contact granted or revoked consent. | contactId, scope, status, previousStatus, source, at |
| tag.added | A tag was added to a contact. | contactId, tag |
Templates and numbers
| Event | When it fires | data |
|---|---|---|
| template.status_changed | WhatsApp approved, rejected or re-rated a template. | templateId, name, language, category, previousStatus, status, qualityScore, rejectedReason |
| channel.status_changed | A number's connection, quality or limit changed. | channelId, previousStatus, status, qualityRating, messagingLimit |
| campaign.completed | A campaign finished or was cancelled. | campaignId, name, outcome, stats, finishedAt |
| Event | When it fires | data |
|---|---|---|
| webhook.test | Sent when you press Send test. | message |
Contact imports and merges do not fire one event per contact, to avoid floods. Media bytes and costs are never included.
Reference and tools
Every endpoint, parameter, schema and error, generated from the same definitions the server enforces. The reference is in English.
In Postman or Insomnia, choose Import, then Link, and paste the openapi.json address. Generators such as openapi-generator turn the same file into a typed client. /api/v1/openapi.json
Frequently asked questions
Which plans include the API?
The REST API and webhooks are included in Pro and Business. Pro allows 3 active keys and 60 requests per minute, Business 10 keys and 300 per minute. Starter and trial workspaces cannot create keys.
Does the API bypass WhatsApp's rules?
No. Sending goes through the same checks as the inbox: the 24-hour window, approved templates and customer consent. A request that would break a rule is rejected with a 422 and a reason, before anything reaches Meta.
How do I avoid sending a message twice?
Send an Idempotency-Key header, for example a UUID you store with your order. If the request times out, repeat it with the same key and body: you get the original response and the customer gets one message.
What happens if my server is down?
We retry up to seven times over about 32 hours. Every attempt is logged with status code, duration and response. If it still fails, the delivery is marked failed and you can resend it, with the same event ID, from the app or the API.
Can I call the API from a browser or mobile app?
No. Keys are secrets and the API deliberately has no CORS. Call it from your own backend, and let your front end talk to your backend.
How do I rotate or revoke credentials?
Revoking an API key takes effect immediately. Webhook secrets can be rotated in the app: the old secret keeps signing next to the new one for 24 hours, so you can deploy the change without dropping events.