Guides
Webhooks

Webhooks

Set up the callback with the hub.challenge handshake, choose the subscribed fields and learn the envelope of every webhook.

Mimicr sends your callback the same webhooks as Meta: a JSON POST, signed with the app secret, for every event of every subscribed field.

Callback verification

Before saving the URL, Mimicr runs Meta's handshake:

text
GET https://seu-servidor.example.com/webhooks/whatsapp?hub.mode=subscribe&hub.verify_token=meu-token-de-verificacao&hub.challenge=1389737617

Your app checks hub.verify_token and answers 200 with the hub.challenge as the body, nothing else:

javascript
app.get("/webhooks/whatsapp", (req, res) => {
  if (req.query["hub.mode"] === "subscribe" && req.query["hub.verify_token"] === process.env.WHATSAPP_VERIFY_TOKEN) {
    return res.status(200).send(req.query["hub.challenge"]);
  }
  res.sendStatus(403);
});

Set up the URL in one of these ways:

  • In the console, under Webhooks ("Verify and save").
  • With the control API: PUT /v1/whatsapp/{slug}/webhooks/callback with {"url", "verify_token"}. It answers 200 with the handshake result, or 422 with what your app answered.
  • With the Graph API, as a tech provider would: Subscribe the app with override_callback_uri and verify_token. If the handshake fails, it answers 2200.

DELETE /v1/whatsapp/{slug}/webhooks/callback turns the callback off. Without a callback, events are recorded as skipped.

Fields

FieldSubscribed by defaultWhen
messagesYesIncoming messages and statuses of sent ones
message_template_status_updateYesTemplate review
message_template_quality_updateYesTemplate quality
template_category_updateYesRecategorization
message_template_components_updateYesTemplate edit
phone_number_quality_updateYesNumber quality and limit
account_updateYesAccount events
user_preferencesYesThe customer stopped or resumed marketing
phone_number_name_update, account_review_update, account_alerts, business_capability_update, flows, security, smb_message_echoesNoOnly through the test emitter
bash
curl --request PUT \
  --url https://api.mimicr.dev/v1/whatsapp/docs/webhooks/fields \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "account_update": false, "flows": true }'

Events of unsubscribed fields are recorded as skipped with the reason.

Envelope

json
{
  "object": "whatsapp_business_account",
  "entry": [{
    "id": "313255174969123",
    "changes": [{
      "field": "messages",
      "value": {
        "messaging_product": "whatsapp",
        "metadata": { "display_phone_number": "555532704202", "phone_number_id": "424361664134261" },
        "contacts": [{ "profile": { "name": "Ana Ribeiro" }, "wa_id": "5511987654321" }],
        "messages": [{ "from": "5511987654321", "id": "wamid.HBgNNTUxMTk4NzY1NDMyMRUCABEYEjY0M0JCNDQ5MzQyMEMxMjVGNQA=", "timestamp": "1793914184", "type": "text", "text": { "body": "Oi, quero saber do meu pedido" } }]
      }
    }]
  }]
}

entry[].id is the WABA of the number or template. Template webhooks carry entry[].time. Each POST carries one event.

Headers

HeaderValue
Content-Typeapplication/json
User-Agentfacebookexternalua
X-Hub-Signature-256sha256= + HMAC-SHA256 of the raw body with the app secret
X-Hub-Signaturesha1= + HMAC-SHA1 of the raw body (legacy)

Answer 200 quickly and process afterwards. See Verify the signature, Incoming messages and Delivery statuses.

Fire a test event

bash
curl --request POST \
  --url https://api.mimicr.dev/v1/whatsapp/docs/webhooks/emit \
  --header 'Authorization: Bearer mk_...' \
  --header 'Content-Type: application/json' \
  --data '{ "field": "account_update", "event": "DISABLED_UPDATE" }'

Any field is accepted; without value, a sample payload goes out. GET /v1/whatsapp/{slug}/webhooks lists the last 50 deliveries with status, attempts and body.