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 /. 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)
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"] });
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"])
{
"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 });
}
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 / 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"
const delivery = await prov.webhooks.test(endpoint.id);
delivery = prov.webhooks.test(endpoint["id"])
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 / 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 / once it's healthy.
Rotate the secret with POST /. 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"
await prov.webhooks.delete(endpoint.id);
prov.webhooks.delete(endpoint["id"])
{ "id": "we_01M5Q9BX757MH61T9G2JN38Z0K", "object": "webhook_endpoint", "deleted": true }
Errors you might see
| Symptom | Cause | Fix |
|---|---|---|
result. 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_ on url | In live, the URL isn't public https | Use a public https URL. |
400 parameter_ on event_ | An unknown event type | Use a type from the table above, or *. |
402 trial_ | The Free trial ended, and webhooks are on Pro and up | Choose a plan in Settings → Plan & usage; see plans and usage. |
See also
- Test webhooks: attempts, resend, replay and the CLI
- Logs and events
- Webhook events: every event type
- Errors
- Step-up approval
- Claim-system connectors, which consume these events for you