The incoming request's headers (any WebhookHeadersInput)
The already-JSON-parsed request body
import { parseWebhookEvent } from 'bitbucket-datacenter-api-client';
app.post('/webhooks/bitbucket', (req, res) => {
const { event, payload } = parseWebhookEvent(req.headers, req.body);
switch (event) {
case 'pr:opened':
console.log('New PR:', payload.pullRequest.title);
break;
case 'repo:refs_changed':
console.log('Pushed refs:', payload.changes.map((c) => c.ref.displayId));
break;
default:
console.log('Unhandled event:', event);
}
res.sendStatus(204);
});
Parses an incoming Bitbucket Data Center webhook delivery into a typed, discriminated BitbucketWebhookEvent, detecting the event type from the
X-Event-Keyheader (falling back to the body'seventKeyfield, which Bitbucket includes on every event exceptdiagnostics:ping).This performs no signature verification and no runtime schema validation —
bodyis trusted as-is (cast to the shape implied by the event key), matching how the rest of this client trusts JSON response bodies. Verify your webhook's shared secret yourself if you configured one.