# Webhooks

> Events B55 sends as candidates move and reports land, how they are signed (Standard Webhooks), and how to verify them.

Source: https://docs.b55.online/webhooks

> **Live jobs:** B55 delivers events to your endpoints over HTTPS, signed, with retries. You add and manage endpoints in the console under **Settings → Webhooks**. **Sandbox:** nothing is sent to your server. Every event is recorded and readable with `GET /v0/jobs/{job_id}/events`, and the console's [playground](http://localhost:3100/playground) shows each one as a signed delivery you can inspect, replay and copy as curl.

## Events

| Event | When | Status |
|---|---|---|
| `candidate.created` | Someone was added by email, or applied through the job's link. | Sandbox |
| `candidate.opened` | The candidate opened the apply link and signed in with GitHub. | Sandbox |
| `candidate.consented` | The candidate consented. | Sandbox |
| `scan.received` | The scan landed. | Sandbox |
| `report.ready` | The report is ready. Fetch it with `report_id`. | Sandbox |
| `report.insufficient_evidence` | Not enough history; a report exists and says so. | Sandbox |
| `candidate.expired` | The candidate never finished. | Planned |
| `consent.revoked` | The candidate withdrew consent; their report and scan were deleted. See [Consent and withdrawal](/consent). | Live |
| `candidate.deleted` | The candidate's record was erased. | Live |

## Payload

The body is the event object, exactly as `GET /v0/jobs/{job_id}/events` returns it:

```json
{
  "object": "event",
  "event_id": "evt_000007",
  "event_type": "report.ready",
  "job_id": "job_000001",
  "candidate_id": "cand_000002",
  "report_id": "rpt_000002",
  "created_at": "2026-11-24T12:47:36.646Z"
}
```

`report_id` is set on `report.ready` and `report.insufficient_evidence`, and `null` on the others. Events are listed oldest first, the order they are delivered.

## Signing

Deliveries follow [Standard Webhooks](https://www.standardwebhooks.com) (the scheme Svix uses), so any Standard Webhooks library can verify them.

| Header | Value |
|---|---|
| `webhook-id` | The `event_id`. Use it to drop duplicates. |
| `webhook-timestamp` | Unix seconds when this attempt was signed. |
| `webhook-signature` | `v1,<base64 HMAC-SHA256>`, space-separated if there are several. |

The signature is HMAC-SHA256 over `<webhook-id>.<webhook-timestamp>.<raw body>`, keyed with your secret (`whsec_<base64>`) after base64-decoding the part after `whsec_`. Reject timestamps more than 5 minutes from now.

Always verify the **raw** body bytes, before any JSON parsing.

### With the SDK

Both SDKs ship the same check as `webhooks.verify` (also `b55.webhooks.verify` / `client.webhooks.verify`). The TypeScript one uses Web Crypto, so it is `async` and runs in Node 20+, edge runtimes and Deno; it accepts a `Headers` object or a plain header record. The Python one takes any header mapping and the body as `bytes` or `str`. Install them as in the [Quickstart](/quickstart#2-create-a-job-and-add-a-candidate).

```ts tab="TypeScript SDK"
import { webhooks } from 'b55';

// Next.js route handler
export async function POST(req: Request) {
  const body = await req.text();
  if (!(await webhooks.verify(process.env.B55_WEBHOOK_SECRET!, req.headers, body))) return new Response('bad signature', { status: 400 });
  const event = JSON.parse(body);
  // ...
  return new Response(null, { status: 204 });
}
```

```python tab="Python SDK"
import os
from flask import Flask, abort, request
from b55 import webhooks

app = Flask(__name__)

@app.post("/webhooks/b55")
def b55_webhook():
    if not webhooks.verify(os.environ["B55_WEBHOOK_SECRET"], request.headers, request.get_data()):
        abort(400)
    event = request.get_json()
    # ...
    return "", 204
```

The tolerance defaults to 300 seconds: `{ toleranceSec: 600 }` in TypeScript, `tolerance_sec=600` in Python.

### Without the SDK

The same check with no dependency, to copy into any codebase:

```ts tab="TypeScript"
import { createHmac, timingSafeEqual } from 'node:crypto';

/** True when one of the v1 signatures matches and the timestamp is within 5 minutes. */
export function verifyB55Webhook(secret: string, headers: Headers, rawBody: string, toleranceSec = 300): boolean {
  const id = headers.get('webhook-id');
  const timestamp = headers.get('webhook-timestamp');
  const signatures = headers.get('webhook-signature');
  if (!id || !timestamp || !signatures) return false;
  const ts = Number(timestamp);
  if (!Number.isFinite(ts) || Math.abs(Date.now() / 1000 - ts) > toleranceSec) return false;
  const key = Buffer.from(secret.replace(/^whsec_/, ''), 'base64');
  const expected = Buffer.from('v1,' + createHmac('sha256', key).update(`${id}.${timestamp}.${rawBody}`).digest('base64'));
  return signatures.split(' ').some((sig) => {
    const given = Buffer.from(sig);
    return given.length === expected.length && timingSafeEqual(given, expected);
  });
}

// Next.js route handler:
// export async function POST(req: Request) {
//   const body = await req.text();
//   if (!verifyB55Webhook(process.env.B55_WEBHOOK_SECRET!, req.headers, body)) return new Response('bad signature', { status: 400 });
//   const event = JSON.parse(body);
//   ...
//   return new Response(null, { status: 204 });
// }
```

```python tab="Python"
import base64, hashlib, hmac, time

def verify_b55_webhook(secret: str, headers, raw_body: bytes, tolerance_sec: int = 300) -> bool:
    """True when one of the v1 signatures matches and the timestamp is within 5 minutes.
    headers: any mapping with case-insensitive get(), e.g. Flask's request.headers."""
    msg_id = headers.get("webhook-id")
    timestamp = headers.get("webhook-timestamp")
    signatures = headers.get("webhook-signature")
    if not msg_id or not timestamp or not signatures:
        return False
    try:
        ts = int(timestamp)
    except ValueError:
        return False
    if abs(time.time() - ts) > tolerance_sec:
        return False
    key = base64.b64decode(secret.removeprefix("whsec_"))
    digest = hmac.new(key, f"{msg_id}.{timestamp}.".encode() + raw_body, hashlib.sha256).digest()
    expected = "v1," + base64.b64encode(digest).decode()
    return any(hmac.compare_digest(expected.encode(), sig.encode()) for sig in signatures.split(" "))

# Flask:
# @app.post("/webhooks/b55")
# def b55_webhook():
#     if not verify_b55_webhook(os.environ["B55_WEBHOOK_SECRET"], request.headers, request.get_data()):
#         abort(400)
#     event = request.get_json()
#     ...
#     return "", 204
```

## Delivery, retries and replay

| | Sandbox | Live |
|---|---|---|
| Where | Shown in the playground's webhook inspector; nothing leaves your machine | POSTed to each endpoint subscribed to the event type |
| Secret | One per job, shown in the playground | One per endpoint (`whsec_…`), shown **once** when you create or rotate it. B55 stores it encrypted and cannot show it again. |
| Guarantee | Every event is listed by `GET …/events` | At least once. Deduplicate on `webhook-id` (the `event_id`). |
| First attempt | | Immediately, when the event happens |
| Retries | None | After a failure B55 retries with growing gaps, roughly 5 seconds, 5 minutes, 30 minutes, 2 hours, 5 hours, then 10 hours, until the 24-hour mark. The schedule may be tuned, so rely on the guarantee rather than the exact gaps. |
| If it keeps failing | | An endpoint that has failed for 24 hours is **disabled and its owners are emailed**. Fix the endpoint, then check its status in Settings → Webhooks. |
| Replay | "Replay" in the inspector re-signs the same event with a fresh timestamp and the same `webhook-id` | Replay from the delivery log in Settings → Webhooks |

An attempt succeeds when your endpoint answers `2xx` within 15 seconds. Answer quickly and do the work afterwards. Because delivery is at least once, the same `webhook-id` can arrive twice; treat a repeat as a no-op.

### Endpoint rules

- HTTPS only, with no username or password in the URL.
- The URL must resolve to a public address. `localhost`, private networks, link-local and cloud metadata addresses are refused, both when you save the endpoint and on every delivery. To test locally, use a tunnel with a public HTTPS URL.
- B55 does not follow redirects; a redirect counts as a failed attempt.
- The body is ids only (see [Payload](#payload)). Fetch details with your API key.
- Verify every delivery with [Standard Webhooks](#signing) before you trust it.
