Replay events
Use this guide to send events again that a receiver never got or lost: events accepted before its subscription existed or while it was paused, or a range a receiver must rebuild from. A replay makes new deliveries, so a delivery that failed is better retried. Replays explains what a replay sends and how a receiver tells it apart.
Before you start
- The
apihelper, from Platform quickstart. - A
devsecret key,key, for a project that adopted EventWolf, from Create a project and issue a key. - An endpoint with a subscription,
endpoint, from Receive webhooks.
This page's code continues the script of the pages above: run its blocks after theirs, in the same file. To run them as a script of their own, first copy each helper from the page that defines it, and set each other value, such as a key or an ID, to one you already have.
1. Preview the replay
To replay a paused window, set from and to to the start and end of the pause. Set target.subscriptionId to replay one webhook subscription or target.endpointId to replay the endpoint’s subscriptions. Choose definitions: 'historical' to use the webhook filter and target in force when each event arrived. Choose definitions: 'current' to apply the filters and targets you have now.
Name the events by a filter and a receipt-time range. Name the target, a webhook subscription or an endpoint, and the definitions to use. This example uses current to match against the endpoint’s non-deleted subscriptions, including paused ones. Send it with dryRun: true first to get a preview without creating a replay.
const replayRequest = {
filter: { types: ['request.resolved'] },
from: new Date(Date.now() - 60 * 60 * 1000).toISOString(),
to: new Date().toISOString(),
target: { endpointId: endpoint.id },
definitions: 'current',
};
const { preview } = await api('POST', '/v1/events/replays', key, {
...replayRequest,
dryRun: true,
});
console.log(preview.counts); // { scanned: 2, matched: 2, deliveries: 2 }
scanned counts the events in the range that meet the filter. matched counts event and subscription pairs. deliveries counts the delivery records the replay would create, including any that would be skipped. Check the counts before step 2. A preview that reaches its scan limit sets partial: true.
2. Run the replay
A replay sends real webhooks, and what it sends can’t be taken back. Run it with the same request, without dryRun:
const { replay } = await api('POST', '/v1/events/replays', key, replayRequest);
console.log(replay.id.slice(0, 4)); // rpl_
It runs in the background. Cancel it to stop it between batches. Deliveries already queued continue normally.
Check it worked
Read the replay until it finishes:
let finished = replay;
for (let wait = 0; wait < 30 && finished.status === 'running'; wait += 1) {
await new Promise((resolve) => setTimeout(resolve, 1000));
({ replay: finished } = await api(
'GET',
`/v1/events/replays/${replay.id}`,
key,
));
}
console.log(finished.status, finished.counts.deliveries); // completed 2
A completed replay has finished creating its deliveries. List deliveries shows their status alongside the endpoint’s other deliveries. Replay deliveries start with a new webhook-id and x-eventwolf-trigger: replay. The event carries its original source and id for deduplication.