Skip to content

Blog · WhatsApp and channels

WhatsApp Cloud API webhook: events, verification and retries

How the WhatsApp Cloud API webhook works: verification, signature, messages and statuses, errors, 7-day retries and deduplication. And with Meteor IA.

Equipo editorial de Meteor Published 8 min read

How does the WhatsApp Cloud API webhook work?

Meta sends a POST to your URL for every incoming message and for every status change of what you sent. Before that, when you save the URL, it verifies it with a GET that carries hub.challenge: you answer 200 with that value if the hub.verify_token matches. Every POST carries the X-Hub-Signature-256 signature, an HMAC-SHA256 of the body keyed with the app secret. You can tell an incoming message because it has the messages array, and a status (sent, delivered, read, failed) because it has statuses. If you do not answer 200, Meta retries for up to 7 days, so you deduplicate by message id. With Meteor IA, Meteor receives that webhook for you and delivers signed events such as contact.message.received.

This guide covers the WhatsApp Cloud API webhook from end to end: what you subscribe to, how Meta verifies it, what each notification carries and what to do about retries. The server code, with Express and with Flask, is already in the tutorials with Node.js and with Python; it is not repeated here. At the end, the same thing with Meteor IA’s events.

1. What you subscribe to: the fields

The Cloud API webhook is not a single one: you subscribe field by field from your Meta app’s dashboard. In an app created with the Connect with customers through WhatsApp use case, the path is Use cases → Customize → Configuration. According to Meta’s documentation:

  • messages carries the messages people send you and the status of the ones you send. It is the one almost every integration uses. It needs the whatsapp_business_messaging permission, as does calls.
  • message_template_status_update tells you when Meta approves, rejects or changes the status of a template. This one and the other fields (number quality, account alerts, template category changes, among others) need whatsapp_business_management.

The app has to be in Live mode: Meta warns that some webhooks are not sent in development mode.

2. Verification: a GET with hub.challenge

Every time you save or change the callback URL or the verify token, Meta calls your URL like this:

GET https://your-server.com/webhook?hub.mode=subscribe&hub.challenge=1158201444&hub.verify_token=the-token-you-typed

If hub.verify_token matches the one stored on your server, you answer 200 with the value of hub.challenge in the body. If not, any status other than 200. Until this works, Meta sends you nothing.

3. The signature on every POST

Every notification arrives as a POST with Content-Type: application/json and the X-Hub-Signature-256: sha256=… header: an HMAC-SHA256 of the body, computed with your app’s app secret. You compute the same hash and compare it with what comes after sha256=. If it does not match, you discard the event.

Two details that cost hours:

  • The signature is over the raw body. If your framework turns the JSON into an object and serializes it again before you verify, the bytes change and the signature stops matching.
  • The URL needs a valid TLS certificate. Meta does not accept self-signed certificates. If you want to restrict who calls you, Meta recommends mTLS rather than an IP allowlist, because its addresses change.

4. What a notification carries

They all share the same envelope. This is an incoming text message, shaped like the example in Meta’s reference:

{
  "object": "whatsapp_business_account",
  "entry": [
    {
      "id": "<WhatsApp Business account ID>",
      "changes": [
        {
          "field": "messages",
          "value": {
            "messaging_product": "whatsapp",
            "metadata": {
              "display_phone_number": "<your business number>",
              "phone_number_id": "<Phone Number ID>"
            },
            "contacts": [
              { "profile": { "name": "Ana" }, "wa_id": "<phone>", "user_id": "<BSUID>" }
            ],
            "messages": [
              {
                "from": "<phone>",
                "from_user_id": "<BSUID>",
                "id": "wamid.…",
                "timestamp": "<unix>",
                "type": "text",
                "text": { "body": "Hi, do you ship to Medellín?" }
              }
            ]
          }
        }
      ]
    }
  ]
}

What is worth reading from it:

  • entry[].id is the WhatsApp Business account and value.metadata.phone_number_id the number that received the message. If you handle several numbers, that is the field that tells you which one.
  • messages or statuses. A message someone sends you has the messages array; the status of a message you sent has statuses. That is how you tell them apart.
  • type changes the rest of the object: text carries text.body, and each type (image, audio, button…) has its own reference in Meta’s documentation. A message the API does not support arrives with type: "unsupported".
  • Identify the person by their BSUID, not by phone number. Meta always includes user_id and from_user_id, but wa_id and from can be missing when the person adopted a username and their phone number is unavailable. An integration that only reads the phone number cannot process those messages.
  • One POST can carry several updates, up to 1,000, and Meta notes that batching is not guaranteed. Walk through entry, changes and the whole array on every POST. A payload can be up to 3 MB.

5. The statuses of what you send

Each message you send can trigger several status webhooks, each with the message id (the wamid the send returned). The values of status, according to Meta’s reference:

statusWhat it means
sentIt left WhatsApp’s servers.
deliveredIt reached the person’s phone.
readIt was displayed in the open chat.
playedThe person played a voice message for the first time.
failedIt could not be sent or delivered. Carries errors.

Three things that are not obvious:

  1. read can arrive without delivered. If the person reads the message as soon as it arrives, Meta does not send the delivery one: it is implied.
  2. pricing (and conversation, when present) comes in only one of the status webhooks: either in sent or in delivered/read, never both. If you track what Meta charges you, do not count it twice.
  3. A failed carries errors[] with code, title, message, error_data.details and href. The code tells you what to do, for example:
    • 131026: it could not be delivered (the number is not on WhatsApp, the person has not accepted the terms or their app is outdated).
    • 131049: Meta did not deliver a marketing message because of the per-user message limit; if you suspect that limit is the cause, it suggests waiting at least 24 hours before resending the template.
    • 132012: the variable values do not match the template’s format.

6. Retries and duplicates

If your server does not answer 200, Meta retries: immediately and then with decreasing frequency over 7 days. After 7 days it drops what you did not acknowledge, and there is no API to fetch past webhooks. Three rules follow from that:

  1. Answer 200 fast and process afterwards. Store the event, answer and do the heavy work (calling your CRM or an AI model) outside the request.
  2. Deduplicate. An incoming message is identified by its id; a status, by the message id plus the status, because the same message gets one webhook per status.
  3. Store on arrival. What did not make it into your database when it arrived cannot be recovered.

7. The same with Meteor IA’s events

With Meteor IA you connect the line once from the dashboard (Channels → WhatsApp) and Meteor receives Meta’s webhook. You subscribe to named events from the workspace with POST /webhook-endpoints (scope webhooks:manage) or with the SDK’s met.webhooks.subscriptions.create. For WhatsApp, the ones that match the above:

What Meta’s webhook carriesThe Meteor IA eventScope
messages: someone wrote to youcontact.message.received, with contact_id, content, message_type and attachmentsconversations:read
What went out to the personcontact.message.sent, with who sent it (the Met, a person, a flow or your integration)conversations:read
statuses with failedcontact.message.failed, with WhatsApp’s error.code (131026, 131049, 132012…)conversations:read
message_template_status_updatechannel.template.approved, .rejected and .status_updatedchannels:read
Number quality and limitschannel.health_updatedchannels:read

What changes compared with Meta’s webhook:

  • There is no GET verification. You get the secret (whsec_…) once when you create the subscription. To test the URL, POST /webhook-endpoints/{id}/test sends you a ping delivery, signed just like a real one.
  • The signature comes in X-Met-Signature: t=<timestamp>,v1=<hmac>, a hex HMAC-SHA256 of <timestamp>.<raw body> keyed with your secret. During a secret rotation two v1 values arrive, and either one is valid. The SDK verifies it with met.webhooks.constructEvent (TypeScript) or construct_event (Python), and by default rejects a signature older than 5 minutes, so nobody can replay an old delivery to you. If your tool does not use the SDK, this is the math:
import crypto from 'node:crypto';

// rawBody: the body exactly as it arrived, without re-serializing the JSON.
function meteorSignatureIsValid(rawBody, header, secret, toleranceSec = 300) {
  if (!header) return false;
  const parts = header.split(',').map((p) => p.trim().split('='));
  const t = Number(parts.find(([k]) => k === 't')?.[1]);
  if (!t || Math.abs(Date.now() / 1000 - t) > toleranceSec) return false;
  const expected = Buffer.from(
    crypto.createHmac('sha256', secret).update(`${t}.${rawBody}`).digest('hex'),
  );
  return parts
    .filter(([k]) => k === 'v1')
    .map(([, v]) => Buffer.from(v ?? ''))
    .some((v) => v.length === expected.length && crypto.timingSafeEqual(v, expected));
}
  • The retries are published. If you do not answer 2xx within 15 seconds, Meteor retries at 1 min, 5 min, 30 min, 2 h and 6 h: six attempts in total. Each one carries the same event id, also in the X-Met-Event-Id header, so you can deduplicate. Order is not guaranteed: sort by the created field.
  • What failed can be requested again. With POST /webhook-endpoints/{id}/deliveries/{deliveryId}/retry or POST /events/{id}/replay, within the 30 days the event log keeps each event.
  • There is no event for each delivered or read. Only failures go out as an event (contact.message.failed). If you need to know whether a message arrived or was read, look it up by its wamid with GET /channels/{channelId}/whatsapp/messages/{waMessageId} (scope channels:read): it returns sent, delivered, read, played or failed, with the error code when there is one, or sending/retrying while it goes out.

The full endpoint, with the subscription, the signature and retry handling, is in the receive signed events in your backend recipe, and the catalog of the 46 events is in the portal’s webhooks guide.

What you have to run on each path

Cloud API webhookMeteor IA events
Registering the URLYour Meta app’s dashboard, with GET verificationPOST /webhook-endpoints or the dashboard, no GET
SignatureX-Hub-Signature-256 with the app secretX-Met-Signature with the subscription secret and its timestamp
What you getmessages and statuses for each number, in batchesOne event per fact: message received, sent or failed, template, number health
RetriesUp to 7 days, intervals not publishedSix attempts over about 8.6 hours, with manual retry
Recovering what was lostNot possiblePOST /events/{id}/replay, up to 30 days
Answering with AIYou build itA Met, with autopilot on

If you do not have the API yet, start with what the WhatsApp Business API is and how to get it. If you are deciding between running the Cloud API yourself and using Meteor, the portal’s Cloud API or Meteor guide compares both paths for builders.

The limits

What this article does NOT answer

We would rather say it here than leave you hunting for something that is not there.

Keep going

What this article mentions, in detail

The integrations, the Mets and the automations named above, each with its own page.

Where it comes from

Sources

Everything this article claims that we did not measure ourselves, with its origin.

Frequently asked

Questions on this topic

Check four things: that the URL is public and has a valid TLS certificate (self-signed ones do not work), that the GET verification returned 200 with the hub.challenge, that you are subscribed to the messages field and that the app is in Live mode: according to Meta, some webhooks are not sent in development mode.

Meta does not publish the intervals. It says it retries immediately and then with decreasing frequency over 7 days; after 7 days it drops what you did not acknowledge. That is why the same event can reach you more than once.

By the array inside value: messages is a message from the person; statuses is the status of a message you sent (sent, delivered, read, failed or played). A status does not carry the message content, only its id.

Because, according to Meta, if the person reads the message as soon as it arrives, the delivered webhook is not sent: delivery is implied by the read.

No. Meta has no API to fetch past webhooks: what you did not store when it arrived is lost. With Meteor IA, a failed delivery can be sent again with POST /events/{id}/replay, within the 30 days the event log keeps each event.

No. You register the URL through the API or the dashboard and get the secret once. To test it, POST /webhook-endpoints/{id}/test sends you a ping delivery, signed just like a real one.

Keep reading

Other articles on the same thing

Want to see it running on your operation?

See the API, the SDK and the MCP server, or message us and we will help with your first subscription.