Skip to content
CirrusDocs

Guides

Webhooks and signatures

Get told about every delivery, bounce and complaint, and check that each call really came from Cirrus.

Register an endpoint#

POST /v1/webhooks needs the webhook:manage scope. Give it the url to call, an optional description (at most 200 characters) and the event_types you want. Leave event_types out or empty to receive every event type except opens and clicks.

curl -X POST https://api.cirrusmail.example/v1/webhooks \
  -H "Authorization: Bearer $CIRRUS_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "url": "https://shop.example/hooks/cirrus",
    "description": "Order emails",
    "event_types": ["email.delivered", "email.bounced"]
  }'
  • The URL must be https, without a user name or password in it, and its host must resolve to public addresses only. An address on a private network, a loopback address or a cloud metadata address is refused when you register it and again at every delivery. Redirects are never followed.
  • The answer carries signing_secret, beginning whsec_. It is shown once; store it right away. It cannot be read again, only replaced from the dashboard.
  • An organisation can have at most 20 endpoints (409 webhook_limit_reached). The API does not de-duplicate registrations, so do not retry one blindly: it could create two endpoints.

Events#

Webhook event types
TypeSent when
email.sentThe email provider accepted the message.
email.deliveredThe recipient's mail server accepted it.
email.bouncedA hard bounce. The address is suppressed.
email.delivery_delayedA soft bounce or a delay.
email.complainedThe recipient marked it as spam. The address is suppressed.
email.cancelledA sending rule stopped it before it left.
email.failedThe email provider refused it.

Two more types, email.opened and email.clicked, come from the open and click tracking of marketing and promotional email. They are sent only to endpoints that name them, never to an endpoint that receives “every event”, because there are many more of them. Their data also carries classification (human, proxy or suspected_bot), reason and, for clicks, link_url and link_index.

From the dashboard you can send a test event, of type webhook.test, to check your receiver without sending any email. Email sent from mailboxes (the business stream) raises no webhooks.

What a delivery looks like#

Cirrus sends a POST with a JSON body. The body has the event's id, its type, when it was created, and data: the email, the recipient it is about, the recipient's status after the event, and when it happened.

Body of a delivery
{
  "id": "0194c2d4-8a3e-7c11-b6a2-5d9f0e4a7b21",
  "type": "email.delivered",
  "created_at": "2026-01-15T09:30:04Z",
  "data": {
    "event_id": "0194c2d4-6f10-7a52-9e3b-2c8d1f0a4b67",
    "email_id": "b3c1f5a4-7d2e-4c8a-9a1b-0e6f2d4a8c11",
    "recipient": "ann@example.org",
    "stream": "transactional",
    "status": "delivered",
    "occurred_at": "2026-01-15T09:30:04Z",
    "test_mode": true
  }
}
Fields of data for email events
FieldMeaning
event_idThe ID of the event in your history, the one GET /v1/events lists. Use it to ignore an event you have already handled.
email_idThe ID the send returned. Use it with GET /v1/emails/{id}.
recipientThe address the event is about.
streamThe email's stream.
statusThe recipient's status after this event.
occurred_atWhen it happened, in UTC.
detailMore about the event, such as a bounce reason, at most 500 characters. Left out when there is none.
test_modetrue if a test key sent the email.

Three headers come with every delivery:

Headers of a delivery
POST /hooks/cirrus HTTP/1.1
Content-Type: application/json
Webhook-Id: 0194c2d4-8a3e-7c11-b6a2-5d9f0e4a7b21
Webhook-Timestamp: 1768469404
Webhook-Signature: v1=3b1f…
  • Webhook-Id identifies one delivery. It is the same on every retry of that delivery, and new on a replay.
  • Webhook-Timestamp is when this attempt was signed, in Unix seconds. It is fresh on every retry.
  • Webhook-Signature is v1= and the signature in hex. While a secret is being replaced it can hold several, separated by spaces.

Verify the signature#

Anyone who finds your URL can post to it. The signature is how you know a call came from Cirrus and was not changed on the way. Check it before you read anything in the body.

  1. Read the raw request body, the exact bytes received. Re-encoded JSON will not match.
  2. Build the message <timestamp>.<raw body>: the Webhook-Timestamp value, a full stop, then the body.
  3. Compute HMAC-SHA256 of that message, using your whole signing secret, whsec_ prefix included, as the key. Write the result in lower-case hex and put v1= in front.
  4. Compare it with each value in Webhook-Signature using a constant-time comparison. Any match passes.
  5. Reject the call if the timestamp is more than five minutes from your own clock, in either direction. This stops someone replaying a call they recorded.

The libraries do all of this in one call; the receiver below uses them.

import express from "express";
import { verifyWebhook, WebhookVerificationError } from "@cirrus-mail/cirrus";

const app = express();

// The signature covers the exact bytes that were sent, so read the body raw.
app.post("/hooks/cirrus", express.raw({ type: "application/json" }), (req, res) => {
  try {
    verifyWebhook({
      secret: process.env.CIRRUS_WEBHOOK_SECRET!,
      timestamp: req.header("Webhook-Timestamp") ?? "",
      signature: req.header("Webhook-Signature") ?? "",
      body: req.body, // a Buffer
    });
  } catch (error) {
    if (error instanceof WebhookVerificationError) return res.sendStatus(400);
    throw error;
  }

  const event = JSON.parse(req.body.toString("utf8"));
  console.log(event.type, event.data.email_id, event.data.recipient);
  res.sendStatus(200);
});

app.listen(3000);

Checking by hand#

Useful for debugging, or for a language without a library:

Compute a signature with OpenSSL
# SECRET is your whsec_ signing secret. TIMESTAMP and BODY are the
# Webhook-Timestamp header and the raw request body, exactly as received.
printf '%s.%s' "$TIMESTAMP" "$BODY" | openssl dgst -sha256 -hmac "$SECRET" -hex
# The 64 hex characters after the equals sign, with "v1=" in front,
# must match a value in the Webhook-Signature header.

To test your own code, this input must give this signature:

Test vector
secret     whsec_testsecret0123456789
timestamp  1700000000
body       {"id":"evt_1","type":"email.delivered"}
signature  v1=e75940b1ca99f98bdf45ae27fa0662cbc4d2baa8f2ba081779190809f71ac549

Answer, then work#

Answer with any 2xx status as soon as you have stored the event, and do slow work afterwards. By default Cirrus waits 10 seconds for an answer. A redirect, a timeout, a connection error or any other status counts as a failure.

Retries and duplicates#

A failed delivery is tried again, each time signed afresh: after 30 seconds, 2.5 minutes, 12.5 minutes and one hour, then every six hours, for up to eight attempts over about a day. After that the event is marked failed. You can send it again from the dashboard, with the same Webhook-Id; a gap of a few minutes in your receiver loses nothing.

Replaying events#

If your receiver was down, or you added an endpoint after the mail was sent, you can send past events to it again. This is done from the dashboard, on the Webhooks page: open the endpoint and choose Replay events. It is not part of the API, so there is no key to give it.

  • Choose a time range of at most 7 days, ending now or earlier. Times in the dashboard are in your own time zone.
  • Choose which events: by default those the endpoint subscribes to, or a list of types you pick, even types the endpoint does not subscribe to. Choose all mail, live mail only or test mail only.
  • At most 1,000 events are sent in one replay. If more match, nothing is sent and the dashboard tells you how many did, so you can choose a shorter range or fewer types. You can start at most 5 replays in 10 minutes.
  • Mail sent from mailboxes is never replayed, and a delivery or delay that was reported twice is replayed once. Opens and clicks are replayed every time they happened. A replay may find nothing, which is not an error.

Each replayed event is a new delivery, with its own Webhook-Id. It is signed, checked and retried like any other. Its data is what the original carried, with occurred_at the original time, plus replayed: true. Its event_id is the same as the original's, and the same every time that event is replayed.

Body of a replayed delivery
{
  "id": "0194f7a1-2b9c-7d40-8e15-a3c6b0d92e48",
  "type": "email.delivered",
  "created_at": "2026-01-16T08:02:11Z",
  "data": {
    "event_id": "0194c2d4-6f10-7a52-9e3b-2c8d1f0a4b67",
    "replayed": true,
    "email_id": "b3c1f5a4-7d2e-4c8a-9a1b-0e6f2d4a8c11",
    "recipient": "ann@example.org",
    "stream": "transactional",
    "status": "delivered",
    "occurred_at": "2026-01-15T09:30:04Z",
    "test_mode": true
  }
}
// After verifyWebhook has accepted the call:
const event = JSON.parse(req.body.toString("utf8"));
const eventId = event.data.event_id;

// Keep handled ids in your database, with a unique index, not in memory.
if (await alreadyHandled(eventId)) return res.sendStatus(200);

await handle(event);
await markHandled(eventId);
res.sendStatus(200);

Replace a signing secret#

You can replace an endpoint's secret from the dashboard. The old secret stops working immediately: every delivery that starts afterwards, retries of earlier events included, is signed with the new one only. Update your receiver at once. Until you do it will reject the deliveries, and they are retried on the schedule above, so a gap of minutes loses nothing.

Next#

Read Idempotency and retries for the same care on the sending side, and Bounces, complaints and suppression for what happens to an address after a bounce event.