Skip to main content

How to test a webhook with Postman

To test a webhook with Postman, copy a real delivery’s body into a POST request aimed at your endpoint, sign it in a collection-level pre-request script so signature verification stays on, and save each failure case (unsigned, stale, bad signature, duplicate) as its own request with a test script. Newman then runs the whole collection in CI.

Postman covers the receiving half only. It sends requests and cannot listen for them, so a capture tool or tunnel supplies the real deliveries you copy from. For testing strategy beyond Postman, including tunnels and monitoring, see the webhook testing guide.

Receiving webhooks?
Svix Ingest is a reliable webhook receiver. It verifies signatures, absorbs delivery spikes, and gives you one endpoint for webhooks from any provider. Start receiving webhooks with Svix Ingest.

Step 1: Set up the collection and environment​

Create a collection called Webhooks and an environment called local with two variables: base_url set to http://localhost:3000, and webhook_secret set to your test endpoint’s signing secret. Give webhook_secret the secret type and put it in the current value, which stays on your machine, rather than the initial value, which is shared with anyone who can see the environment. If you use Postman in a browser instead of the desktop app, requests to localhost also need the Postman Desktop Agent running.

Add a request with the method POST and the URL {{base_url}}/webhooks, the route of your webhook endpoint. Set the body to raw JSON, which makes Postman send Content-Type: application/json, and paste in a real payload rather than one you invented. Every provider dashboard keeps a log of recent deliveries, so copy one from there and your specimen matches production byte for byte.

Step 2: Sign every request in a collection pre-request script​

Put the signing code on the collection, under Scripts > Pre-request, so every request in it gets a fresh signature at send time. Senders that follow the Standard Webhooks specification compute HMAC-SHA256 over id.timestamp.body, keyed with the base64-decoded part of the secret after whsec_, and Postman’s sandbox ships CryptoJS for exactly this:

const testCase = pm.request.headers.get('x-test-case');
pm.request.headers.remove('x-test-case');

if (testCase === 'oversized') {
pm.request.body.update({ mode: 'raw', raw: JSON.stringify({ pad: 'x'.repeat(2 * 1024 * 1024) }) });
}

const id = testCase === 'duplicate'
? pm.collectionVariables.get('last_webhook_id')
: `msg_${pm.variables.replaceIn('{{$guid}}')}`;
const timestamp = Math.floor(Date.now() / 1000) - (testCase === 'stale' ? 3600 : 0);
const body = pm.variables.replaceIn(pm.request.body.raw);

const secret = CryptoJS.enc.Base64.parse(pm.environment.get('webhook_secret').replace(/^whsec_/, ''));
let signature = CryptoJS.HmacSHA256(`${id}.${timestamp}.${body}`, secret).toString(CryptoJS.enc.Base64);
if (testCase === 'bad-signature') {
signature = (signature[0] === 'A' ? 'B' : 'A') + signature.slice(1);
}

pm.collectionVariables.set('last_webhook_id', id);
if (testCase !== 'unsigned') {
pm.request.headers.upsert({ key: 'webhook-id', value: id });
pm.request.headers.upsert({ key: 'webhook-timestamp', value: String(timestamp) });
pm.request.headers.upsert({ key: 'webhook-signature', value: `v1,${signature}` });
}

x-test-case is a header you add to the failure-case requests in the next step. The script reads it, removes it so your endpoint never sees it, and bends the signature accordingly. upsert rather than add matters when you resend a request: add stacks a second webhook-signature header on top of the stale one. The body goes through pm.variables.replaceIn before signing because Postman substitutes {{variables}} at send time, and the signature has to cover the bytes that actually leave.

Step 3: Save one request per failure case​

Replaying a good event proves almost nothing. Duplicate the valid request once per case below, add the x-test-case header where the table says so, and keep the duplicate case directly after the valid delivery so it reuses that delivery’s ID.

RequestChange from the valid requestExpected response
Valid deliverynone2xx in under one second
Duplicatex-test-case: duplicate2xx, and no second side effect
Unsignedx-test-case: unsigned401
Stale timestampx-test-case: stale401
Bad signaturex-test-case: bad-signature401
Malformed JSONbody cut off mid-object400, not 500
Oversized bodyx-test-case: oversized413

The duplicate case exists because retries make duplicates routine, and deduplication on webhook-id is the fix. The stale case backdates the timestamp by an hour, which is your replay attack protection and the reason timestamp tolerance exists. The malformed body is still signed, so it gets past verification and tests what your parser does with garbage.

Each request then gets a post-response script that asserts the expected status. For the valid delivery:

pm.test('accepted', () => pm.expect(pm.response.code).to.be.within(200, 299));
pm.test('answers in under a second', () => pm.expect(pm.response.responseTime).to.be.below(1000));

For the rejection cases, pm.test('rejected', () => pm.response.to.have.status(401)); is the whole script. The one-second budget is deliberate: a correct handler hands work to a background job and responds at once, and a two-second response in Postman is a timeout waiting to happen when a real sender is on the other end. If your service exposes the record the event changes, follow the duplicate with a GET and assert the change happened once.

Step 4: Cover every event type with a data file​

The Collection Runner can repeat a request once per row of a CSV file, substituting the columns into the body. Use a body like {"type": "{{event_type}}", "data": {"id": "{{object_id}}"}} and a file like this:

event_type,object_id
invoice.paid,in_1042
invoice.payment_failed,in_1043
customer.subscription.deleted,sub_88

Because the pre-request script resolves the body before signing, every iteration is signed over its own bytes. A handler that silently returns 200 for an event type it does not recognize passes this run, so assert on whatever response body or side effect tells you the event was routed.

Step 5: Run the collection in CI with Newman​

Newman is Postman’s command-line runner, and it takes an exported collection and environment directly. Pass the secret from your CI secret store rather than committing it in the environment file:

npm install -g newman
newman run webhooks.postman_collection.json \
--environment ci.postman_environment.json \
--env-var "webhook_secret=$WEBHOOK_TEST_SECRET" \
--reporters cli,junit \
--bail

Point base_url at a service your pipeline just booted, and signature regressions fail the build instead of production. Raw-body handling is the classic catch: verification needs the exact bytes that arrived, and a JSON middleware that re-serializes the body breaks it in a way only an end-to-end request notices.

Signing for Stripe and GitHub​

Providers that predate Standard Webhooks need a different script body, but the same collection structure. Stripe signs {timestamp}.{body} with the full whsec_ string as the key, used as-is rather than base64-decoded, and sends a hex digest in Stripe-Signature. GitHub signs the body alone with the secret you chose and sends sha256= plus a hex digest in X-Hub-Signature-256:

const body = pm.variables.replaceIn(pm.request.body.raw);
const t = Math.floor(Date.now() / 1000);

const stripeSig = CryptoJS.HmacSHA256(`${t}.${body}`, pm.environment.get('stripe_secret')).toString(CryptoJS.enc.Hex);
pm.request.headers.upsert({ key: 'Stripe-Signature', value: `t=${t},v1=${stripeSig}` });

const githubSig = CryptoJS.HmacSHA256(body, pm.environment.get('github_secret')).toString(CryptoJS.enc.Hex);
pm.request.headers.upsert({ key: 'X-Hub-Signature-256', value: `sha256=${githubSig}` });
pm.request.headers.upsert({ key: 'X-GitHub-Event', value: 'push' });
pm.request.headers.upsert({ key: 'X-GitHub-Delivery', value: pm.variables.replaceIn('{{$guid}}') });

Keep only the half you need. The GitHub webhook example shows the headers and payloads GitHub really sends, which is the specimen to paste into the body.

Capture what a real sender sends​

Postman can only push requests out, so to see what a provider actually sends you need something publicly reachable. A capture tool such as Svix Play gives you a URL that records every delivery with its headers, which you then copy into Postman as your specimen. A tunnel such as ngrok does the same for code already running on your laptop. Postman mock servers cover a narrower case: they return canned responses at a public URL and log the calls, which is useful when you are the sender and want to see your own requests land.

When a delivery has already gone wrong in production, debugging webhooks is the better starting point. And if you would rather not own signature verification and delivery durability at all, Svix Ingest handles the receiving side.

Frequently asked questions

Can Postman receive a webhook?

No. Postman sends HTTP requests, it does not listen for them, so a provider cannot deliver to it. Use a capture tool such as Svix Play or a tunnel such as ngrok to receive real deliveries, then copy the payload and headers into a Postman request.

How do I sign a webhook request in Postman?

Use a collection-level pre-request script. CryptoJS is available in Postman's sandbox, so you can compute HMAC-SHA256 over the provider's signed string and set the signature, message ID, and timestamp headers with pm.request.headers.upsert before each request is sent.

Should I disable signature verification when testing?

No. Verification is the part of a webhook handler most likely to break, and raw-body bugs only show up when it is switched on. Sign test requests with a test secret instead, so verification stays enabled everywhere.