How do I verify webhook data is correct?
Compare what you stored with the sender's own record of the same objects, by id, over a fixed window. Fetch the objects from the sender's API for that window, look each one up in your store, and count three things: objects you never stored, rows the sender does not have, and fields whose values differ. Zero in all three is the evidence that the data is correct; a handler that returned 200 is evidence only that it ran.
The comparison
// Reconcile stored rows against the sender's own record of the same window.
// source: objects fetched from the sender's API; stored: your rows for that window
// key: the id field both sides share; fields: the fields you copy and expect to match
export function reconcile ({ source, stored, key, fields }) {
const mine = new Map(stored.map((row) => [row[key], row]))
const theirs = new Set(source.map((obj) => obj[key]))
const missing = []
const mismatched = []
for (const obj of source) {
const row = mine.get(obj[key])
if (!row) { missing.push(obj[key]); continue }
const differ = fields.filter((f) => JSON.stringify(row[f]) !== JSON.stringify(obj[f]))
if (differ.length) mismatched.push({ id: obj[key], fields: differ })
}
const extra = stored.filter((row) => !theirs.has(row[key])).map((row) => row[key])
return { missing, extra, mismatched, correct: !missing.length && !extra.length && !mismatched.length }
}Pick the window and the fields
Use a window that has closed: every delivery in it has succeeded or stopped retrying, so an event still in flight is not counted as missing. Compare only the fields you copy; a field you never store is not a mismatch.
Run it on a schedule
Run the comparison every day over the previous closed window and alert when any list is not empty. A handler that fails loudly gets fixed; a handler that writes the wrong value gets found by this or by a customer.
When a mismatch turns up
Trace it to the event that wrote the row. Slashbin stores each event's raw payload next to the transform's output and every delivery attempt, so a wrong value leads back to the exact event and the stage that produced it, and replay re-runs that event once the cause is fixed.
Need somewhere for the next project's webhooks to land? Slashbin's Free plan takes an account, not a card.
Start Free
(opens in a new tab)