# Receive webhook events

Receive signed, retried webhook events when claims escalate, approvals resolve, tokens are revoked or canaries trip, and verify each delivery's signature.

Use webhooks to hear about events as they happen instead of polling, for example when a claim escalates, an approval is decided or a canary trips. Provenance sends each event to your endpoint as a signed POST, and retries until your endpoint answers with a 2xx.

**Before you begin:** export the sandbox account key. In the sandbox an endpoint can be `http://localhost`; in live, it must be a public `https` URL.

```bash
export PROVENANCE_API=https://sandbox-api.provenanceauth.com
export PROVENANCE_KEY=prv_test_acct_P9xN2vQ7bT4mW8sYd3cFjLh6gAe1kR5
```

## 1. Choose the events

Every event type, with the product that sends it and when, is listed in [Webhook events](https://provenanceauth.com/docs/reference/webhook-events.md).

Subscribe to the types you need, or `["*"]` for all. You receive events only for products your account has.

## 2. Create an endpoint

Create one with [`POST /v1/webhook_endpoints`](https://provenanceauth.com/docs/api/webhooks.md#post-v1-webhook-endpoints). The response has the endpoint's signing `secret`, shown only this once:

**curl**

```bash
curl -s $PROVENANCE_API/v1/webhook_endpoints \
  -H "Authorization: Bearer $PROVENANCE_KEY" \
  -H "Content-Type: application/json" \
  -d '{ "url": "http://localhost:4242/webhooks", "event_types": ["mandate.approval.approved", "mandate.assessment.denied"] }' | tee endpoint.json
export ENDPOINT_ID=$(jq -r .id endpoint.json)
```

**Node**

```ts
import { Provenance } from "@provenanceauth/sdk";

const prov = new Provenance({ apiKey: process.env.PROVENANCE_KEY!, baseUrl: process.env.PROVENANCE_API });
const endpoint = await prov.webhooks.create({ url: "http://localhost:4242/webhooks", eventTypes: ["mandate.approval.approved", "mandate.assessment.denied"] });
```

**Python**

```python
import os
from provenanceauth import Provenance

prov = Provenance(os.environ["PROVENANCE_KEY"], base_url=os.environ["PROVENANCE_API"])
endpoint = prov.webhooks.create(url="http://localhost:4242/webhooks", event_types=["mandate.approval.approved", "mandate.assessment.denied"])
```

```json
{
  "id": "we_01M5Q9BX757MH61T9G2JN38Z0K",
  "object": "webhook_endpoint",
  "url": "http://localhost:4242/webhooks",
  "event_types": ["mandate.approval.approved", "mandate.assessment.denied"],
  "status": "active",
  "disabled_reason": null,
  "secret": "whsec_cpTkhJ944OQwxfZQDxrL2vi50HO1QKQg"
}
```

## 3. Verify each delivery

Every delivery is a POST with this body:

```json
{
  "id": "evt_01M5Q9C2NP0YTKFZFXQGKQP9QC",
  "object": "event",
  "type": "mandate.approval.approved",
  "created_at": "2026-10-24T15:44:49.334Z",
  "environment": "sandbox",
  "account_id": "acct_000000000000000000000000000000a2",
  "data": { "approval_id": "appr_01M5Q25QP84QHATMRDGSGQ459K", "status": "approved" }
}
```

The `Provenance-Signature` header is `t=<unix time>,v1=<hex HMAC-SHA256>` over `<t>.<raw body>`, keyed by the endpoint's secret. Check it against the raw body before you parse the JSON; re-serializing changes the bytes and breaks the signature.

After a [leaked secret](https://provenanceauth.com/docs/account/if-a-key-leaks.md) is rotated, the header carries two `v1` values for 24 hours, one from each secret. Accept the delivery when any `v1` matches; the SDK verifiers do.

**Node**

```ts
import { verifyWebhookSignature } from "@provenanceauth/sdk";

export async function handle(req: Request): Promise<Response> {
  const rawBody = await req.text();
  const result = await verifyWebhookSignature(rawBody, req.headers.get("provenance-signature"), process.env.PROVENANCE_WEBHOOK_SECRET!);
  if (!result.valid) return new Response(result.reason, { status: 400 });
  const event = JSON.parse(rawBody);
  return new Response(null, { status: 200 });
}
```

**Python**

```python
import json, os
from provenanceauth import verify_webhook_signature

def handle(raw_body: str, signature_header: str) -> int:
    result = verify_webhook_signature(raw_body, signature_header, os.environ["PROVENANCE_WEBHOOK_SECRET"])
    if not result.valid:
        return 400
    event = json.loads(raw_body)
    return 200
```

Answer with a 2xx quickly and do the work afterwards. Deliveries are at least once, so dedupe on the event `id`, which is also sent as the `Provenance-Event-Id` header and stays the same across retries.

## 4. Send a test event

[`POST /v1/webhook_endpoints/{id}/test`](https://provenanceauth.com/docs/api/webhooks.md#post-v1-webhook-endpoints-id-test) sends a signed `ping` to the endpoint and returns the delivery:

**curl**

```bash
curl -X POST $PROVENANCE_API/v1/webhook_endpoints/$ENDPOINT_ID/test \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
const delivery = await prov.webhooks.test(endpoint.id);
```

**Python**

```python
delivery = prov.webhooks.test(endpoint["id"])
```

The response, trimmed:

```json
{
  "id": "dlv_01M5Q9C2NPJSFGS6C5SY9CQ2ZB",
  "object": "webhook_delivery",
  "event_type": "ping",
  "attempts": 1
}
```

`status` is `delivered` when your endpoint answered 2xx, or `failed` with `last_error` and `next_attempt_at` when it didn't. [`GET /v1/webhook_endpoints/{id}/deliveries`](https://provenanceauth.com/docs/api/webhooks.md#get-v1-webhook-endpoints-id-deliveries) lists every delivery, as does **Webhooks → Deliveries** in the console; open one to see each attempt and your endpoint's answer, and resend it ([test webhooks](https://provenanceauth.com/docs/integrate/test-webhooks.md)). Finished deliveries (`delivered` or `exhausted`) and their attempts are kept 30 days on every plan; pending and retrying ones are kept until they finish.

## 5. Handle retries and rotation

A delivery that gets a non-2xx or no answer within 10 seconds is retried after 1 minute, 5 minutes, 30 minutes, 2 hours and 8 hours, then marked `exhausted`. An endpoint with repeated exhausted deliveries is disabled, with a `disabled_reason`; re-enable it with [`PATCH /v1/webhook_endpoints/{id}`](https://provenanceauth.com/docs/api/webhooks.md#patch-v1-webhook-endpoints-id) once it's healthy.

Rotate the secret with [`POST /v1/webhook_endpoints/{id}/rotate_secret`](https://provenanceauth.com/docs/api/webhooks.md#post-v1-webhook-endpoints-id-rotate-secret). The old secret stops verifying at once, so update your handler first or accept both briefly. When you're done testing, delete the endpoint:

**curl**

```bash
curl -X DELETE $PROVENANCE_API/v1/webhook_endpoints/$ENDPOINT_ID \
  -H "Authorization: Bearer $PROVENANCE_KEY"
```

**Node**

```ts
await prov.webhooks.delete(endpoint.id);
```

**Python**

```python
prov.webhooks.delete(endpoint["id"])
```

```json
{ "id": "we_01M5Q9BX757MH61T9G2JN38Z0K", "object": "webhook_endpoint", "deleted": true }
```

## Errors you might see

| Symptom | Cause | Fix |
| --- | --- | --- |
| `result.valid` is `false` | The body was parsed or re-encoded before checking, or the secret is wrong or rotated | Check the raw bytes with the current secret. |
| `400` [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid) on `url` | In live, the URL isn't public `https` | Use a public https URL. |
| `400` [`parameter_invalid`](https://provenanceauth.com/docs/platform/errors.md#parameter_invalid) on `event_types` | An unknown event type | Use a type from the table above, or `*`. |
| `402` [`trial_ended`](https://provenanceauth.com/docs/platform/errors.md#trial_ended) | The Free trial ended, and webhooks are on Pro and up | Choose a plan in **Settings → Plan & usage**; see [plans and usage](https://provenanceauth.com/docs/account/plans-and-usage.md#free-trial). |

## See also

- [Test webhooks](https://provenanceauth.com/docs/integrate/test-webhooks.md): attempts, resend, replay and the CLI
- [Logs and events](https://provenanceauth.com/docs/integrate/logs-and-events.md)
- [Webhook events](https://provenanceauth.com/docs/reference/webhook-events.md): every event type
- [Errors](https://provenanceauth.com/docs/platform/errors.md)
- [Step-up approval](https://provenanceauth.com/docs/mandate/guides/step-up-approval.md)
- [Claim-system connectors](https://provenanceauth.com/docs/attest/guides/connectors.md), which consume these events for you
