Replay a webhook with curl

Replaying a webhook means sending your server a request identical to the provider's, as many times as needed, without triggering the original event again. With a captured request and curl, the "change the code, replay, observe" loop takes seconds.

Why replay instead of re-triggering

Re-triggering a real event (a payment, a push, an order) is slow and sometimes costly. Replaying gives you a stable input: the same request on every try, which makes a bug reproducible and a fix verifiable.

1. Capture the original request

Set the Tracehook capture URL as the webhook endpoint and trigger the event once. In the inspector, "Copy as cURL" produces a command with the received method, headers and body. The JSON export keeps the full request for a ticket or an automated test.

2. Replay against your server

Replace the capture URL with your server's (local or staging). The copied command embeds the body verbatim with --data-raw. If you'd rather keep the body in a file, send it with --data-binary @file: unlike -d @file, which strips newlines, it sends the file byte for byte and preserves the signature.

Replaying a GitHub event
curl -i -X POST 'http://localhost:3000/webhooks/github' \
  -H 'Content-Type: application/json' \
  -H 'X-GitHub-Event: push' \
  -H 'X-GitHub-Delivery: 72d3162e-cc78-11e3-81ab-4c9367dc0958' \
  -H 'X-Hub-Signature-256: sha256=<signature-captured>' \
  --data-binary @body.json

3. Replay pitfalls

A replayed request isn't quite the original one:

  • Host and Content-Length: let curl compute them, don't copy them.
  • Timestamped signatures: Stripe rejects a signature whose t= is too old (5 minutes by default in its libraries). For a late replay, sign again with your test secret, or disable the tolerance locally only.
  • Side effects: a replay really runs your code (emails, database writes). Replay against a test database.
  • Compression headers: if the original request carried Content-Encoding, send the captured body as is, or drop the header.

4. Replay in a loop to test idempotency

Providers can deliver the same event more than once. Replay the same request several times in a row: your server must answer 2xx every time and apply the effect only once.

Multiple replay
# Replay the same request 3 times to check idempotency
for i in 1 2 3; do
  curl -s -o /dev/null -w '%{http_code}\n' -X POST 'http://localhost:3000/webhooks/github' \
    -H 'Content-Type: application/json' -H 'X-GitHub-Event: push' \
    --data-binary @body.json
done

Provider tools

GitHub offers "Redeliver" in the webhook's "Recent Deliveries" tab. Stripe can resend an event from the Dashboard or with the Stripe CLI, which can also forward events to your machine. These tools send a fresh, correctly signed request; a curl replay stays faster for iterating on a frozen request.

Stripe CLI
stripe listen --forward-to localhost:3000/webhooks/stripe
stripe events resend evt_1234567890

Capture a real request, replay it as often as you need.

No sign-up