Skip to content

Webhooks

Webhooks send a signed HTTPS POST to a URL of yours whenever a run changes status, so you can connect Zenfra to chat, paging or your own tooling without polling the API. One request is sent per run event that matches the endpoint's filter.

Creating an endpoint

Organization admins manage endpoints under Integrations → Webhooks, through the API (/api/v1/webhook-endpoints) or with the Terraform resource.

Field Description
URL An https:// URL, at most 2,048 characters, with no user name or password and no #fragment
Description Optional, at most 200 characters
Event types At least one; see Event types
Enabled On by default

An organization can have up to 10 endpoints.

The URL's host is resolved when you save it and again before every request. Zenfra refuses an address in a private, loopback, link-local (including cloud metadata), shared (carrier-grade NAT), documentation, benchmarking, multicast, reserved or other special-use range, for IPv4 and IPv6. An IPv4-mapped IPv6 address is judged by the IPv4 address it carries, and the 6to4, Teredo and NAT64 translation ranges are refused. A host whose answers include any refused address is refused as a whole. Saving such a URL fails with webhook_url_blocked; a host that does not resolve fails with webhook_url_unresolvable (fix the DNS record and retry). If a host starts resolving to a refused address later, requests to it fail with the error class blocked_address and are not retried.

Redirects are not followed: a 3xx response is a failed delivery. Response bodies are read up to 64 KiB, discarded and never stored.

The signing secret

Zenfra generates the endpoint's secret and shows it once, when you create the endpoint. It looks like whsec_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8=. Store it in your receiver's configuration; Zenfra cannot show it again.

Rotate secret replaces it at once and shows the new secret once. A request that was already in flight when you rotated may still carry a signature made with the old secret; accept both briefly if that matters to you. The delivery log is kept across a rotation.

Event types

Event type Sent when the run becomes
run.queued QUEUED (run created or retried)
run.claiming, run.preparing, run.initializing picked up by a worker and set up
run.planning PLANNING
run.awaiting_approval AWAITING_APPROVAL (a plan waits for approval)
run.applying, run.destroying, run.performing applying, destroying or running a task
run.finished FINISHED
run.failed FAILED
run.cancelled CANCELLED
run.skipped SKIPPED
run.dead_letter DEAD_LETTER (failed with no retries left)
run.policy_reevaluated not a status change: the run's plan policies were evaluated again

The dashboard offers two presets: Failures and approvals (run.failed, run.awaiting_approval, run.dead_letter) and All.

What an endpoint receives is decided when Zenfra hands the event to the endpoint, normally within seconds of the run's change: its filter and enabled switch at that moment apply. An endpoint never receives events from before it was created. An event handed off while the endpoint was disabled is not sent to it, now or later, and leaves no entry in its delivery log; an event still waiting to be handed off when you enable the endpoint again is sent under the endpoint's settings at that moment. A delivery already in its log that comes due while the endpoint is disabled fails with endpoint_disabled; you can Redeliver it.

The request

POST /your/path HTTP/1.1
Content-Type: application/json
User-Agent: Zenfra-Webhooks/1
webhook-id: 01K7RR2CHVZENFRAWEBHKTEST0
webhook-timestamp: 1760693400
webhook-signature: v1,wvbF1EWDKxP5tSu3bPzoxzllJXoZvlJ0gqvyJM+qOc8=
Zenfra-Event-Type: run.failed
Zenfra-Event-Revision: 7
Zenfra-Delivery-Id: 6710f3a2c9e1b20001a1b2c3
Header Meaning
webhook-id The event id. The same event always carries the same id, including on retries and redeliveries
webhook-timestamp When this attempt was sent, in Unix seconds
webhook-signature v1, followed by the signature; see Verifying a request
Zenfra-Event-Type The event type (also in the body)
Zenfra-Event-Revision The run's event revision (also in the body); absent on a test event
Zenfra-Delivery-Id The delivery log entry this request belongs to

The body (shown here formatted; it is sent compact):

{
  "id": "01K7RR2CHVZENFRAWEBHKTEST0",
  "type": "run.failed",
  "schema_version": 1,
  "occurred_at": "2025-10-17T09:30:00.123Z",
  "organization_id": "652f00000000000000000001",
  "data": {
    "stack": {"id": "652f00000000000000000002", "name": "network-prod"},
    "run": {
      "id": "652f00000000000000000003",
      "revision": 7,
      "status": "FAILED",
      "previous_status": "APPLYING",
      "run_type": "TRACKED",
      "trigger_source": "vcs_push",
      "delta": {"add": 1, "change": 0, "destroy": 0},
      "policy_verdict": "pass",
      "url": "https://app.zenfra.cloud/stacks/652f00000000000000000002/runs/652f00000000000000000003"
    }
  }
}
Field Description
id Event id, the same as webhook-id
type Event type
schema_version 1. A new version will be announced before it is sent
occurred_at When the run's change was committed (RFC 3339, UTC, milliseconds)
organization_id Your organization
data.stack.id, data.stack.name The run's stack; the name is empty if the stack was deleted
data.run.id The run
data.run.revision The run's event revision: it increases by one with every event of that run
data.run.status The run's status after the change
data.run.previous_status The status before it; for run.policy_reevaluated the status it stayed in. Absent when the run was created
data.run.run_type PROPOSED, TRACKED, DESTROY or TASK
data.run.trigger_source What started the run: manual, vcs_push, vcs_pull_request or drift, when recorded
data.run.delta The plan's change counts, once a plan exists
data.run.policy_verdict The plan policy verdict once evaluated: pass, advisory, fail or error
data.run.url The run in the dashboard

Fields that do not apply are left out. A body never contains error messages, policy findings, log lines, variables or plan output.

Verifying a request

Zenfra signs with the Standard Webhooks scheme, so its libraries for your language work too. The signature is the Base64 HMAC-SHA256 of <webhook-id>.<webhook-timestamp>.<body> keyed with the secret's bytes: the part after whsec_, Base64-decoded. Verify against the raw body bytes, before any JSON parsing, and reject a request whose timestamp is more than a few minutes away from your clock.

Test vector

Your implementation is right if it accepts exactly this request:

Input Value
Secret whsec_AAECAwQFBgcICQoLDA0ODxAREhMUFRYXGBkaGxwdHh8= (the bytes 0 to 31)
webhook-id 01K7RR2CHVZENFRAWEBHKTEST0
webhook-timestamp 1760693400
Body the example body above, compact: no spaces or line breaks
webhook-signature v1,wvbF1EWDKxP5tSu3bPzoxzllJXoZvlJ0gqvyJM+qOc8=

The compact body, exactly:

{"id":"01K7RR2CHVZENFRAWEBHKTEST0","type":"run.failed","schema_version":1,"occurred_at":"2025-10-17T09:30:00.123Z","organization_id":"652f00000000000000000001","data":{"stack":{"id":"652f00000000000000000002","name":"network-prod"},"run":{"id":"652f00000000000000000003","revision":7,"status":"FAILED","previous_status":"APPLYING","run_type":"TRACKED","trigger_source":"vcs_push","delta":{"add":1,"change":0,"destroy":0},"policy_verdict":"pass","url":"https://app.zenfra.cloud/stacks/652f00000000000000000002/runs/652f00000000000000000003"}}}

Python

import base64, hashlib, hmac, time

def verify(secret: str, headers: dict, body: bytes, tolerance: int = 300) -> bool:
    msg_id = headers["webhook-id"]
    timestamp = headers["webhook-timestamp"]
    if abs(time.time() - int(timestamp)) > tolerance:
        return False
    key = base64.b64decode(secret.removeprefix("whsec_"))
    signed = f"{msg_id}.{timestamp}.".encode() + body
    expected = base64.b64encode(hmac.new(key, signed, hashlib.sha256).digest()).decode()
    return any(
        hmac.compare_digest(sig.removeprefix("v1,"), expected)
        for sig in headers["webhook-signature"].split()
        if sig.startswith("v1,")
    )

Node.js

const crypto = require("node:crypto");

function verify(secret, headers, body, toleranceSeconds = 300) {
  const id = headers["webhook-id"];
  const timestamp = headers["webhook-timestamp"];
  if (Math.abs(Date.now() / 1000 - Number(timestamp)) > toleranceSeconds) return false;
  const key = Buffer.from(secret.replace(/^whsec_/, ""), "base64");
  const expected = crypto
    .createHmac("sha256", key)
    .update(`${id}.${timestamp}.`)
    .update(body) // the raw request body (Buffer or string)
    .digest();
  return headers["webhook-signature"].split(" ").some((sig) => {
    if (!sig.startsWith("v1,")) return false;
    const given = Buffer.from(sig.slice(3), "base64");
    return given.length === expected.length && crypto.timingSafeEqual(given, expected);
  });
}

To check either one against the test vector, call it with the vector's values and a tolerance large enough to cover the vector's 2025 timestamp.

Delivery guarantees

  • At least once. An event can arrive more than once (a retry after a lost response, a redelivery). Deduplicate on the event id.
  • No order. Requests are sent in parallel and retried independently, so events can arrive in any order, even for one run. To order one run's events, use revision; the highest revision is the latest state.
  • Gaps are normal. An endpoint that filters event types sees only some revisions of a run.
  • A redelivered event has the same id and body, so a receiver that deduplicates ignores it if it already processed it.

Retries

Any 2xx response is success. These are retried: a timeout (10 seconds per request), a connection, TLS or DNS failure, a 5xx, 408 and 429. Every other 3xx or 4xx response fails the delivery at once, without retries.

Retries back off exponentially from 1 minute, doubling each time up to 2 hours, with 20% jitter. A Retry-After header (seconds or an HTTP date) that asks for longer is honoured, up to 2 hours.

Each delivery is retried for 24 hours after Zenfra hands the event to the endpoint. Time while the endpoint is down, or while Zenfra pauses sending, counts toward that window; a delivery whose window has closed fails with the reason exhausted.

Automatic disable

An endpoint that keeps failing is disabled automatically: after 20 failed attempts in a row, once the first of them is at least 24 hours old. Every attempt counts, so the retries of one delivery can count several times; any successful attempt resets the count. The endpoint then shows Disabled: repeated failures with the time, and the audit log records webhook_endpoint.disabled by the System actor. Deliveries for a disabled endpoint fail with the reason endpoint_disabled.

Both conditions must hold, so an endpoint that receives few events may not be disabled even when every delivery fails; it is a heuristic, not a deadline.

Fix the receiver, then enable the endpoint again. Enabling, changing the URL or rotating the secret resets the failure count. Events handed off while the endpoint was disabled are not sent to it; deliveries already in its log can be redelivered.

The delivery log

Each endpoint has a delivery log, newest first, kept for 30 days. A delivery shows its state (pending, in_flight, succeeded, failed), the event type, run and revision, the number of attempts, the last response code, the last error class, the time of the last and the next attempt, and its last ten attempts.

Error class Meaning
timeout No response within 10 seconds
connection The connection could not be made or was cut
tls The TLS handshake or the certificate check failed
dns The host did not resolve
blocked_address The host resolved to a refused address; not retried
http_status The receiver answered with a status other than 2xx; see the response code
rate_limited Held back by Zenfra's rate limit; no attempt was used
endpoint_disabled The endpoint was disabled when the delivery was due
unconfirmed An attempt began but its result was not recorded (for example, Zenfra restarted), so whether the request was sent or arrived is unknown

A failed delivery's reason is its error class, or exhausted when its retry window closed: 24 hours after handoff, or one hour for a redelivery or a test event.

Redeliver queues a finished delivery (succeeded or failed) for one more attempt with the same event id and body, even if the event is older than 24 hours; the endpoint must be enabled. A redelivery is retried for an hour if Zenfra cannot start the attempt, but makes at most one request.

Send test event queues a webhook.test event for one attempt:

{"id":"01K7S0ABCDEFGHJKMNPQRSTVWX","type":"webhook.test","schema_version":1,"occurred_at":"2026-10-17T09:00:00.000Z","organization_id":"652f00000000000000000001","data":{"endpoint_id":"6710f3a2c9e1b20001a1b2c4"}}

It is signed like any other event and has no Zenfra-Event-Revision header.

Rate limits

Zenfra sends at most about 60 requests per minute to one endpoint (bursts of 10) and 300 per minute per organization (bursts of 50), with at most two requests in flight per endpoint. A delivery held back by a limit waits without using an attempt. The limits are approximate and can briefly reset when Zenfra restarts.

Terraform

The zenfra_webhook_endpoint resource manages an endpoint:

resource "zenfra_webhook_endpoint" "oncall" {
  url         = "https://hooks.example.com/zenfra"
  description = "Failures to the on-call channel"
  event_types = ["run.failed", "run.awaiting_approval", "run.dead_letter"]
}

output "webhook_secret" {
  value     = zenfra_webhook_endpoint.oncall.secret
  sensitive = true
}

The secret attribute is set when Terraform creates the endpoint and kept in state; it is empty for an imported endpoint. An apply on an endpoint that was disabled automatically enables it again (enabled defaults to true). Secret rotation is done in the dashboard or the API.