Fire a webhook when a mock is served
Before you begin
- Plan
- Included in Pro and Team. How plans and limits work
- Role
- Admin or higher.
- You need
- A mock in the project to fire the webhook
Many APIs answer at once and report the outcome later: 202 Accepted now, and a callback when the payment settles. Binding a webhook to a mock reproduces that. Each time the mock answers a request, the webhook fires after the delay you set, and its body can carry values from that request.
-
Open the project’s Webhooks tab.
-
Select Edit on the webhook. To start from scratch, select New webhook and fill in where it goes as in Send webhooks from a project.
-
Under What fires it, open When a mock is served and choose the mock. Type part of its name or path to search all the project’s mocks.
-
In Wait before calling (seconds), enter how long to wait after the mock answers, from
0to900. The wait starts once the caller has the answer, after any delay on the mock, so the callback never arrives first. This delays only the callback, never the mock’s answer. -
To put values from the request in the callback, write a Body template, such as:
{ "type": "order.paid", "orderId": "{{request.body.id}}", "at": "{{firedAt}}" } -
Select Save changes, or Create webhook for a new one.
-
Send a request that the mock matches to the project’s address.
With the template above on a mock for POST /orders, this request:
curl -X POST https://orders-api.mockhub.dev/orders \ -H 'Content-Type: application/json' \ -d '{"id": "ord_7", "total": 42}'gets the mock’s answer at once, and after the delay your receiver gets:
{ "type": "order.paid", "orderId": "ord_7", "at": "2026-09-30T09:41:07+00:00" }What the callback can use
Section titled “What the callback can use”A delivery fired by a mock has the cause mock-served, in its X-MockHub-Cause header and in the standard envelope. Without a template, the standard envelope names the mock, the request’s method and path, and the status the mock answered with.
In a template, these placeholders read the exchange that fired the webhook: mock.id, mock.name, request.method, request.path, request.url, request.body, request.body. followed by a path into a JSON body, request.query. followed by a parameter name, request.header. followed by a header name, and response.status. It can also read what the mock answered: response.body, response.body. followed by a path into a JSON answer, and response.header. followed by a header name. Body template placeholders describes each one.
Report back a value the mock generated
Section titled “Report back a value the mock generated”A callback often carries what the answer held, such as the id a mock generated. For a POST /jobs mock whose templated answer returns { "jobId": "{{random.uuid}}", "status": "processing" }, the callback body
{ "jobId": "{{response.body.jobId}}", "status": "done", "at": "{{firedAt}}" }sends the same id the caller received. To model both stages, add a second webhook on the same mock with a short delay for processing and another for done; several webhooks can share one trigger.
A webhook reads the answer from the moment you save it with a body template that uses a response.body or response.header placeholder. Requests the mock served before that carry no answer for the webhook, so their deliveries fail as described under Limits.
Send the callback to the address the request gives
Section titled “Send the callback to the address the request gives”Real APIs often take the callback address from the request, such as a callback_url in the body. To do the same, select Edit on the webhook, set Send it to to The address the request gives, and choose where to read it:
-
Under Read it from, choose Body field, Query parameter or Header, and enter the field’s name, such as
callback_url. -
Under Allowed hosts, select Add host and list every host the address may name, such as
hooks.acme.test, or.acme.testfor its subdomains. -
Select Save changes.
The webhook now sends to whatever address that field holds, in the request that fired it. The option is available once the webhook fires When a mock is served and has no schedule.
- A host must be listed to be called.
.example.commatches its subdomains and notexample.comitself. Any port is allowed on a listed host. A public suffix such as.co.uk, an IP address or a name without a dot is refused when you save. - The project’s own inbox is always allowed, so
https://<project>.mockhub.dev/__inbox/...needs no matching entry. A request-derived target still requires at least one host in Allowed hosts; a fixed inbox target needs none. See Receive callbacks in the project inbox. - When the request has no such field, the field is not an
http://orhttps://address, or its host is not listed, the delivery is Failed, for example withThe callback URL from {{request.body.callback_url}} names a host this webhook does not allow.The reason never quotes the address. - Custom headers on the webhook go to whichever listed host the request names, and never to the project’s own inbox: a delivery there carries none, because anyone who can read the project sees what the inbox receives.
- Send a test is unavailable, because a test has no request to read the address from. Serve the trigger mock instead.
- Deliveries shows From the request beside the address, and the address as the request log keeps it: when the log does not keep that value, the placeholder text shows instead. Replay sends to the same address, and is refused if the host has since left the list.
Detach the trigger, or delete the mock
Section titled “Detach the trigger, or delete the mock”A mock that fires a webhook cannot be deleted, even while the webhook is paused. The attempt, from the app or from an AI assistant, is refused with:
Webhook "Order created" fires when this mock is served. Detach the trigger before deleting the mock.To detach it, select Edit on that webhook, open When a mock is served and choose No mock — fire it by hand or on a schedule, then select Save changes. The mock can then be deleted.
Result
Section titled “Result”The webhook’s line reads, for example, 5 seconds after “Create order” is served, or When “Create order” is served with no delay. Each request the mock answers adds a delivery with the cause A mock was served under Deliveries. It shows Pending while the delay runs, then the outcome.
Limits
Section titled “Limits”- It fires for every request the mock answers, with no condition on the request, including each response of a response sequence. To fire only for some requests, make a separate mock that matches only those.
- It fires only when the mock answers on the project’s address: not for Try it in the mock editor, not for a request no mock matched and never for an Inactive mock. In Record everything mode mocks are not consulted, so it fires only when the project falls back to its mocks because no upstream is set or the upstream allowance is used up.
- A callback reads at most 256 KiB of the mock’s answer. A template that reads
response.bodywhen the answer is larger fails the delivery withThe mock's response was 300000 bytes; a callback reads at most 262144., and a delivery whose answer was not kept fails withThis request's response was not captured for callbacks: it was served before this webhook read responses, or with a request too large to carry it. - The response placeholders read the answer the caller received, and are empty for a delivery fired by hand or by a schedule. Under Deliveries they show as the request log keeps them, so a redacted header reads
[REDACTED]there. - A request whose method, address, headers and body together exceed 1 MiB still gets the mock’s answer, but its delivery is Failed with
Callback request context exceeds the 1 MiB limit.rather than sent with part of the request. - It fires whatever the project’s logging settings, even with Store request logs off.
- The request placeholders read the request as it arrived, before any redaction the logging settings apply.
{{request.header.Authorization}}sends your caller’s credentials to the webhook’s target. - The delivery’s record shows no more of the request than its request log does: under Deliveries, the body shows those values as the request log keeps them, so a redacted header reads
[REDACTED]there. The body as it was sent is kept with the record for a retry or a replay, and is not shown. - A request body that is not UTF-8 text cannot go into the callback. A template that places one fails the delivery with
The rendered webhook body is not UTF-8 text, so it cannot be kept for retries and replays., or inside a quoted JSON string withThe value of {{request.body}} is not UTF-8 text, so a JSON body cannot carry it. - A webhook has one trigger mock; several webhooks can share one. The delay is at most 900 seconds; for anything longer or repeated, use a schedule.
- Each fire spends the plan’s delivery allowance. Once it is used up, the mock still answers but no callback is sent, and nothing appears under Deliveries.