Bitbucket Data Center API Client
    Preparing search index...

    Function parseWebhookEvent

    • Parses an incoming Bitbucket Data Center webhook delivery into a typed, discriminated BitbucketWebhookEvent, detecting the event type from the X-Event-Key header (falling back to the body's eventKey field, which Bitbucket includes on every event except diagnostics:ping).

      This performs no signature verification and no runtime schema validation — body is 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.

      Parameters

      Returns BitbucketWebhookEvent

      If no event key can be determined from either the headers or the 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);
      });