View as Markdown

Integrate · Guide

Receive webhook events

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.

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.

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. The response has the endpoint's signing secret, shown only this once:

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)
{
  "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:

{
  "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 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.

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 });
}

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 sends a signed ping to the endpoint and returns the delivery:

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

The response, trimmed:

{
  "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 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). 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} once it's healthy.

Rotate the secret with 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 -X DELETE $PROVENANCE_API/v1/webhook_endpoints/$ENDPOINT_ID \
  -H "Authorization: Bearer $PROVENANCE_KEY"
{ "id": "we_01M5Q9BX757MH61T9G2JN38Z0K", "object": "webhook_endpoint", "deleted": true }

Errors you might see

SymptomCauseFix
result.valid is falseThe body was parsed or re-encoded before checking, or the secret is wrong or rotatedCheck the raw bytes with the current secret.
400 parameter_invalid on urlIn live, the URL isn't public httpsUse a public https URL.
400 parameter_invalid on event_typesAn unknown event typeUse a type from the table above, or *.
402 trial_endedThe Free trial ended, and webhooks are on Pro and upChoose a plan in Settings → Plan & usage; see plans and usage.

See also