Receive call events with webhooks
Summary
This guide registers a webhook endpoint for call events and verifies the signature of each request to it. It also tests the endpoint, resends deliveries, rotates the secret, and replaces, disables or deletes the endpoint. It does not list the event payloads; see Webhook events.
Facts
Steps
Set WEBHOOK_URL to the HTTPS URL of your receiver, for example https://hooks.example.com/rasen.
1. Create an endpoint
The answer is 201 with the endpoint, its ETag and its signing secret. Store the secret in
your secret store now: no other answer returns it. A replay of the same Idempotency-Key and body
answers 201 with "secret": null and Idempotent-Replayed: true. Set ENDPOINT_ID to the id
of the endpoint.
2. Verify the signature in your receiver
This code runs in your receiver, not against the API. Give it the stored secret, the three
webhook-* request headers (with lower-case names) and the exact request body bytes, before you
parse the JSON. A Standard Webhooks library also verifies this signature. Each file ends with a self-check that signs a body with a random test secret.
The Python file prints True and the TypeScript file prints true. The webhook-signature
header holds one or two space-separated v1,<signature> values. During a rotation grace period it
holds one value for each secret. If no value matches, answer with a status that is not 2xx and
do not process the event. Do the same if the timestamp is more than 5 minutes from your clock. If
the signature is valid, answer 2xx.
3. Send a test event
The answer is 201 with the queued delivery of one webhook.test event. Rasen sends it to this
endpoint only, whatever its events list. A disabled endpoint answers 409 conflict with
details.reason: endpoint_disabled.
4. List the deliveries
The answer is one page of deliveries of the last 30 days, newest first. A repeated parameter
matches any of its values; different parameters must all match. state takes pending, held,
delivering, retrying, succeeded, failed and cancelled; event_type takes the four event
types. failed means that all 8 attempts of the current chain failed; last_error_class gives the
class of the last failure. The list never carries a request body, a response body or response
headers. To get the next page, send next_cursor as cursor with the same filters and limit.
5. Resend a delivery
Set DELIVERY_ID to the id of a delivery in state: succeeded or state: failed, from step 4.
The answer is 200 with the delivery in state: pending, chain_no one higher and
attempt_count: 0. Rasen sends the same webhook-id and the same body bytes again, in a new
chain of 8 attempts. created_at of the delivery does not change.
6. Rotate the signing secret
The sample reads the endpoint first and sends its ETag as If-Match.
The answer is 200 with the new secret, once. Store it, and give it to your receiver before
previous_secret_expires_at. The previous secret stays valid for 24 hours. Until then each attempt
carries two signatures, one for each secret, so a receiver with either secret accepts it. A
rotation during a grace period makes the current secret the previous one, with a new 24-hour grace
period. The older previous secret then stops working at once.
7. Replace, disable or enable the endpoint
A replace is a full replacement of url, description, events and enabled: send every field.
An omitted or null description removes the description. This sample disables the endpoint;
send "enabled": true to enable it again.
The answer is 200 with the endpoint and its new ETag. What each change does:
8. Delete the endpoint
The answer is 200 with the endpoint as it was left, with deleted_at set. The endpoint stops
receiving events at once. Rasen cancels its pending, held, delivering and retrying deliveries
(cancel_reason: endpoint_deleted) and destroys every version of its signing secret. An attempt
already in flight is not recalled. After the delete, every operation on the endpoint answers
404 not_found, a second delete included. Delete works in a suspended workspace.
Rules
- MUST store the
secretfromcreateWebhookEndpointandrotateWebhookSigningSecretwhen the answer arrives. Rasen keeps no plaintext copy, and a replay returns"secret": null. - MUST verify
webhook-signatureover{webhook-id}.{webhook-timestamp}.{body}with the exact request body bytes, before you parse the body. - MUST accept the request when any
v1value inwebhook-signaturematches. - MUST refuse a request whose
webhook-timestampis more than 5 minutes from your clock. - MUST deduplicate on
webhook-id. Delivery is at least once, and every attempt, retry and resend of one event carries the samewebhook-idand the same body bytes. - MUST NOT depend on the order of events. Rasen gives no ordering guarantee.
- MUST answer
2xxto accept an event. Any other status, a3xxincluded, or a timeout fails the attempt. - MUST answer
2xxto an eventtypethat you do not know, and ignore it. - MUST read the call with
getCallwhendata.truncatedistrue: the body is in the reduced form. - MUST treat an endpoint
statethat you do not know as not enabled. - MUST send the
ETagof the endpoint asIf-Matchon replace, delete and rotate. After astale_revisionconflict, read the endpoint again and check the change before you send it with the newETag. - MUST send a new
Idempotency-Keyfor each new action, and the same key, body andIf-Matchto retry an action whose answer was lost. - MUST NOT put user information (
user:password@) or a fragment in the endpointurl. A query string is allowed; every workspace member who can read the endpoint sees the wholeurl.
Verify
Run this before you delete the endpoint in step 8. It lists the webhook.test deliveries that
your receiver accepted.
Expected output: at least one item with "state": "succeeded" and a 2xx last_status_code.
Errors
A resend tests its conflict reasons in this order: endpoint_deleted, event_expired,
delivery_cancelled, delivery_in_progress, endpoint_disabled, event_unsubscribed.