Skip to main content
AgentRail signs each webhook delivery with an HMAC signature. Before you process any payload, you must verify that signature against the raw request body and your webhook secret. The parseWebhookEvent function handles verification and deserialization in one call.

Import

Verify and parse a delivery

parseWebhookEvent throws if the signature does not match or if required headers are missing.

Required headers

AgentRail sends all of the following headers with every delivery. Pass them exactly as received — do not normalize or rename them.

Use the raw request body

Pass the raw request body bytes or string to parseWebhookEvent. Do not parse the body as JSON first. JSON re-serialization changes byte ordering and whitespace, which breaks the HMAC signature check.
In Express, read the raw body by configuring express.raw:

Set the webhook secret

Your webhook secret (AGENTRAIL_WEBHOOK_SECRET) is separate from your API key. You set it when you create a webhook subscription — see POST /event-subscriptions for the secret parameter.