Receive webhooks on your machine
Before you begin
- Plan
- Included in Free, Pro and Team. How plans and limits work
- Role
- Editor or higher to listen and Admin or higher to receive posts as sent.
- You need
- The MockHub CLI, version 0.3.0 or newer
- A personal token in the project's workspace
- Code on your machine that receives webhooks, such as a server on `http://localhost:3000`
Give a provider your project’s inbox as its webhook address, and mockhub listen relays each post it sends to an address on your machine as it arrives, so you can run and debug your webhook handler locally without exposing your computer to the internet.
-
Install the CLI, if you have not:
npm install --global @mockhub/cli. See Keep a project’s configuration in a repository for the details. -
Create a personal token in the project’s workspace, with the Editor or Admin role, and give it to the CLI:
Terminal window export MOCKHUB_TOKEN=mh_sk_… -
Open the project’s Webhooks tab and, under This project’s inbox, select the copy button beside the command, named Copy the listen command. The command names the project, so it works in any directory. In a repository with
mockhub.yaml,--env <name>names a target instead of--project. -
Paste the command into a terminal, change
--forward-toto the address your code listens on, and run it:Terminal window mockhub listen --project 0198f6a2-0000-7000-8000-000000000001 --forward-to http://localhost:3000/webhooksIt prints the inbox it listens to and where posts go:
Forwarding https://orders-api.mockhub.dev/__inbox/** → http://localhost:3000/webhooks (as sent) -
In the provider’s dashboard, set the webhook address to the inbox, with a path below it that names the provider if you like, such as
https://orders-api.mockhub.dev/__inbox/stripe. -
Send a test event from the provider, or do what triggers one.
-
When you are done, press Ctrl-C in the terminal.
Result
Section titled “Result”Each post appears in the terminal a moment after the provider sends it, with what your code answered and how long it took:
12:04:05 POST /__inbox/stripe → 200 41 msYour code receives the post at http://localhost:3000/webhooks/stripe. After Ctrl-C the command prints Stopped listening. and exits with code 0. The posts also appear in the project’s request logs under Webhook inbox, as every inbox post does while Store request logs is on.
Where each post goes
Section titled “Where each post goes”The path after /__inbox is added to the path of --forward-to, and the post’s query string follows unchanged.
| The provider posts to | With | Your code receives |
|---|---|---|
/__inbox |
--forward-to http://localhost:3000/webhooks |
/webhooks |
/__inbox/stripe?attempt=2 |
--forward-to http://localhost:3000/webhooks |
/webhooks/stripe?attempt=2 |
/__inbox/stripe/events |
--forward-to http://localhost:3000/hooks --path stripe |
/hooks/events |
/__inbox/github |
--forward-to http://localhost:3000/hooks --path stripe |
Nothing: --path leaves it out |
- The same request. Each post keeps its method, its headers and the exact bytes of its body.
HostandContent-Lengthare set for your address, and the headers MockHub adds, and a private project’s access key, are left out. When you receive posts as sent, a signature the provider computed over the body still checks out. - In order, one at a time. Posts are relayed in the order they arrived, each after your code has answered the one before. Your answer is printed, never sent back to the provider.
--timeout <ms>: how long to wait for your code to answer each post, 30000 by default. A post that waits longer is reported asno answer within … ms, and the next one follows.- An HTTPS address with a certificate your machine does not trust, such as a self-signed one, needs
--skip-verify. It relaxes the check for the--forward-toaddress only, never for MockHub. - Another machine.
--forward-tocan name any address your computer reaches. For one that is not your own machine, the command warns that posts, and any credentials in them, go there.
As sent or as logged
Section titled “As sent or as logged”What you receive depends on your role in the workspace, checked for each post:
| Role | Receives |
|---|---|
| Admin | Each post as sent, whatever the project’s logging settings say |
| Editor | Each post as its request log shows it: headers under Request headers to redact as [REDACTED], and JSON body fields under Body keys to redact in captures or on MockHub’s built-in list of sensitive fields redacted. While Log request headers and body or Store request logs is off, only the method and path |
An Editor’s post is not shortened to the plan’s logged body size: only the redaction differs. The first line says (as sent) or (as logged), and the command names once each header or body it receives redacted, because a signature over it then fails. To check signatures, listen as an Admin, or take the signature header off the project’s Request headers to redact.
A provider that signs the full URL, such as Twilio, signs the inbox address it posted to, not yours. Verify such a signature against the inbox address, which --json prints in its first line as inboxUrl.
Machine-readable output
Section titled “Machine-readable output”--json prints one JSON object a line, as posts arrive, instead of the lines above:
event |
When | Fields |
|---|---|---|
listening |
Once, first | project, sessionId, inboxUrl, forwardTo, delivery (as-sent or as-logged) |
post |
For each post | id, seq, method, path, target, then status and durationMs, or error, or skipped: "tooLarge"; withheld |
missed |
When posts were dropped before reading | count |
warning |
For each warning | message |
stopped |
Once, after Ctrl-C | None |
Limits
Section titled “Limits”- One-way. The provider gets the inbox’s own
200and{"received":true}, never your code’s answer. A provider that checks its webhook address by reading an answer, such as Slack’surl_verificationor Meta’shub.challenge, cannot be served. Give it another path of the project, answered by a mock, or by your code through a tunnel: see Answer requests from code on your machine. - Only what arrives while you listen. Nothing is kept while nobody listens, and a new listener starts after the newest post, so posts sent before the command started never arrive.
- Ten minutes, 25 posts. MockHub keeps a project’s posts for 10 minutes and 25 at most for its listeners. A listener that falls further behind, for example on a laptop that slept, loses the oldest and prints how many, such as
3 posts were dropped before they could be read; the relay keeps 10 minutes and 25 posts. - Up to 1 MiB a post. A larger body, or more than 64 KiB of address and headers, is not relayed: the command prints the post with
over 1 MiB, not relayed; read it in the request log. - No dot segments. A post whose path holds a
.or..segment, such as/__inbox/stripe/../admin, is not relayed, so a post never reaches a path above--forward-toor outside--path. The command prints the post withhas a dot segment, not relayed; read it in the request log. - Three listeners a project, whoever runs them. A fourth is refused with Inbox relay busy. A listener whose command was killed, or whose machine went offline, closes two minutes after it last renewed.
- People only. A machine token, or a personal token created with the Viewer role, is refused with Token scope, so a pipeline cannot listen. A Viewer is refused with Insufficient role, and a plan without the relay with Plan limit. The command prints the reason and exits with code
2. - Within your API allowance. Listening calls MockHub a few times a minute while nothing arrives, and more while posts do. The calls count against your token’s allowance, and every listener you run shares a further allowance of its own. When either runs out, the command says so and waits.
- Live updates make it prompt. When they are unavailable, the command checks for posts every few seconds instead, so posts arrive a little later.
- Sessions are not recorded in the workspace’s Activity.
- On a private project the inbox uses the access policy like every other path, so a provider that cannot send an access key reaches it only from an allowed address.