Skip to main content
Webhooks send event notifications to your endpoint when something happens in Guardian. Guardian uses tiny event payloads that describe what happened. You need to use the API to fetch more details if needed.

How webhooks work

  1. Event occurs: A token operation or system event happens in Guardian.
  2. Notification sent: Guardian sends a webhook payload to your configured endpoint.
  3. Process payload: Your endpoint receives a lightweight event description.
  4. Fetch details: Use the API to fetch full details if needed.

Configuration

Register a webhook with its URL, the event types it subscribes to and an optional HMAC key (see Register webhook). Every webhook subscribed to an event type receives its own copy of each event of that type. Webhooks cannot be edited. To change the URL, the events or the HMAC key, register a new webhook and then delete the old one. Deliveries that are already queued, including their retries, still go to the URL of the deleted webhook. Use a publicly reachable HTTPS URL. Guardian does not deliver to private or reserved IP addresses; such deliveries fail and are retried like any other failed delivery.

Payload

Each notification is a POST request with a JSON body:
See Event notification for the full schema.

Responding to Webhooks

Guardian counts a delivery as successful when your endpoint answers with any 2xx status code, for example 200, 202 or 204, within 15 seconds.
  • Acknowledge first, process later. Store the event and return 2xx right away, then do the work asynchronously. A slow response counts as failed and the event is sent again.
  • Keep the response body empty. Guardian ignores the body. If you do return one with content-type: application/json, it must be valid JSON; otherwise the delivery counts as failed.
  • Every other outcome is a failure. Any status outside 2xx, including 4xx, a timeout, and a connection or TLS error, causes a retry. There is no status code that stops retries.
  • Register the final URL. Guardian follows redirects, but a 301, 302 or 303 redirect turns the request into a GET without the payload.

Retries

Guardian makes up to six attempts per event and webhook. After a failed attempt, it waits before trying again: Each wait varies by up to 10% so retries don’t arrive in lockstep. The last attempt happens about eight minutes after the first. If the sixth attempt fails, Guardian drops the event. The webhook stays active for later events, but failed deliveries cannot be listed or sent again. If your endpoint was unavailable for longer, use the API to bring your data up to date, for example List tokens for network tokens.

Duplicates and Ordering

The same event can arrive more than once, for example when your endpoint processed it but answered too late. Retries carry the same id, the same body and the same signature, so store the id of each processed event and skip events you have already seen. Events are not guaranteed to arrive in the order they occurred. Several deliveries run in parallel, and a retried event can arrive after a newer one. Rather than relying on the order, fetch the resource from related_object.url to read its current state; a deleted network token returns 404.

Security

  • Set an HMAC key when you register the webhook, so you can verify that notifications come from Guardian.
  • Configure secure (HTTPS) endpoints.
  • Validate webhook signatures before processing requests.

HMAC signing

When the webhook has an HMAC key, every notification carries an x-hmac-signature header: the HMAC-SHA256 of the raw request body, encoded as lowercase hex. Guardian uses the key exactly as you registered it, as a string; it is not base64-decoded. Without an HMAC key, the header is not sent.

How to verify

  1. Calculate the HMAC using:
    • The raw payload you received in the webhook body, before any JSON parsing
    • Your HMAC key
    • The SHA256 hashing function
  2. Compare the calculated value with the x-hmac-signature header you received, using a constant-time comparison.
If they match, the webhook was sent by Guardian and was not modified in transmission.

Example

For the HMAC key my-webhook-signing-key and this raw body:
the x-hmac-signature header is:
Verification in Node.js:
Pass the body exactly as received, for example as a Buffer from a raw body parser. Re-serializing parsed JSON can change the bytes and break the signature.