Developer guides
What Is a Webhook? How Webhooks Work, With Examples
What is a webhook: an HTTP request an app sends to your URL when an event happens. How webhooks work, with a real payload to test for free.


What is a webhook? It's an HTTP request that one app sends to a URL you choose, the moment something happens, such as a payment going through or a customer replying on WhatsApp. Instead of your code asking "anything new?" every few seconds, the other app tells you.
People also call it a callback URL or a reverse API. They all mean the same thing: you give a service a URL, and it POSTs to that URL when an event fires.
How a webhook works
- You give the service a URL. In its dashboard or API you add something like
https://example.com/webhooks/paymentsand pick the events you care about. - Something happens. A customer pays, a file finishes uploading, a message arrives.
- The service sends a request. Usually a POST with a JSON body describing the event, plus headers that say what it is and prove where it came from.
- Your server answers. You return a 2xx status within a few seconds. Most services treat anything else, or no answer, as a failure and try again later.
That's the whole mechanism. A webhook is just an HTTP request going the other way: the service calls you, instead of you calling the service.
A webhook example
Hypersender sends this when your WhatsApp number receives a message and the message.any event is on:
POST /webhooks/whatsapp HTTP/1.1
Host: example.com
Content-Type: application/json
Authorization: your-webhook-secret
{
"event": "message.any",
"data": {
"payload": {
"from": "201000000002@c.us",
"fromMe": false,
"body": "Is order #1042 on its way?",
"hasMedia": false
}
}
}Every webhook has the same three parts:
- Method and URL: almost always POST, to the URL you registered.
- Headers: the content type, often the event name, and something to prove the sender: a shared secret, as here, or a signature such as Stripe's
Stripe-Signatureor Meta'sX-Hub-Signature-256. - Body, called the payload: the event data, usually JSON. Some older services send form fields instead, like
From=...&Body=....
Webhook vs API
An API answers when you ask. A webhook calls you when something happens.
With only an API, you'd poll: ask for new messages every ten seconds, which is 8,640 requests a day per number, almost all of them returning nothing. A webhook sends one request per event and arrives within a second.
Most integrations use both: the API to send and fetch, webhooks to hear about changes. There's a longer comparison in webhook vs API.
How to receive a webhook
The receiving end is a normal route in your app. This Flask handler accepts the WhatsApp event above:
import hmac, os
from flask import Flask, abort, request
app = Flask(__name__)
SECRET = os.environ["HYPERSENDER_WEBHOOK_SECRET"]
@app.post("/webhooks/whatsapp")
def whatsapp_webhook():
if not hmac.compare_digest(request.headers.get("Authorization", ""), SECRET):
abort(401)
event = request.get_json()
if event["event"] == "message.any" and not event["data"]["payload"]["fromMe"]:
queue_reply(event["data"]["payload"]) # do the real work in a background job
return {"ok": True}Four habits keep webhook handlers reliable:
- Check the sender first. Compare the secret or verify the signature before you trust the body. The URL alone isn't a secret.
- Answer fast. Return 200 straight away and do slow work, like calling other APIs, in a queue. A handler that takes 30 seconds gets retried and runs twice.
- Expect duplicates. Retries mean the same event can arrive more than once. Store an event ID, or make the action safe to repeat.
- Don't rely on order. Two events can arrive out of sequence, such as "delivered" before "sent". Use timestamps when order matters.
How to test a webhook
The hard part of webhooks is seeing what arrives before your handler exists. A webhook tester solves that: it gives you a temporary URL, you paste it into the service, trigger an event, and read the exact method, headers and body in your browser. Then you write the handler against the real payload instead of the docs' example.
The free Hypersender tester also answers Meta's verification request (hub.challenge), so you can paste it straight into the WhatsApp Cloud API settings and see real message payloads. You can set the status code it returns, too, to check how a service retries after a 500.
When your handler runs on your own machine, a tunnel such as ngrok gives it a public HTTPS address. Webhook services can't reach localhost.
When a webhook doesn't arrive
- The URL isn't public. It must be reachable from the internet over HTTPS.
localhost, private IPs and self-signed certificates usually fail. - Your server answers with an error or too slowly. Check the service's delivery log. Hypersender's Webhook Logs show every attempt, your server's response, and a button to resend.
- The event isn't selected. Many services only send the events you ticked.
- A firewall or bot protection blocks it. Allow the service's IP range, or exclude the webhook route from challenges.
Webhooks in WhatsApp and SMS
For messaging, webhooks are how your app hears back. With Hypersender, incoming WhatsApp messages, delivery and read receipts, reactions, and every SMS your Android phone receives reach your server as webhooks. The WhatsApp webhook guide lists the events and how to answer them, and the WhatsApp bot in Python builds a complete bot on top of one.
Get a free webhook URL to see a request arrive, or start a Hypersender trial to receive your own WhatsApp messages by webhook. The first 14 days are free.





