Events

Webhooks

Verify Ternwire webhook signatures, handle duplicate events, and recover failed webhook deliveries.

On this page

Ternwire sends signed HTTP requests to your webhook endpoint when email events occur. Verify the signature against the exact request bytes, persist the event durably, and deduplicate repeated deliveries before triggering application actions. Webhook delivery is retryable, so the same event can arrive more than once.

Register an endpoint and store its secret

Create an HTTPS endpoint with Add endpoint on the Webhooks page of the dashboard, or with POST /v1/webhook-endpoints. Store the one-time signing secret on your server, and choose the events your application needs to process. See the API reference for the request schema. A URL that Ternwire cannot use returns invalid_webhook_url, and a public address that we cannot reach reports the reason url_not_reachable.

Enabled endpoints receive matching events from both test and live sending. Test-recipient events carry data.mode: "test", so check that field before triggering live business actions. Live events do not include a mode field. Workspaces that send newsletters can also choose contact and broadcast events.

Each endpoint's menu on the Webhooks page can edit its URL and events, disable it, create a new signing secret, or delete it. A disabled endpoint receives no new requests, and its waiting retries continue when you enable it again. After you create a new signing secret, new events are signed with it at once, while retries of earlier events keep the old secret, so accept both until those finish.

Use a public HTTPS destination that responds directly. Redirects are not followed as successful deliveries. Never expose the signing secret through browser code or public environment variables.

Events

Each delivery event is about one recipient of one email. An email to three people produces events for each of them.

EventWhen it is sentIn the dashboard
email.submittedWe handed the email to our sending provider.Handed off
email.deliveredThe recipient's mail server accepted the email.Delivered
email.delayedThe recipient's mail server asked us to try again later. We keep trying.Delayed
email.bouncedThe recipient's mail server refused the email. A permanent bounce also blocks the address.Bounced
email.complainedThe recipient marked the email as spam. The address is blocked.Marked as spam
email.rejectedOur sending provider refused to send it, usually because of a virus or a blocked kind of attachment.Rejected
email.submission_unknownWe couldn't tell whether the provider accepted the email. It may still arrive.Needs attention

Every request body has the same envelope. data holds the email's message ID, the recipient's ID and address, and when the provider reported the event:

{
  "id": "customer_event_recipient_7d2e4f0a9b1c4d8e_bounced",
  "type": "email.bounced",
  "createdAt": "2026-11-08T12:00:05.000Z",
  "data": {
    "version": 1,
    "type": "email.bounced",
    "messageId": "msg_3f2b1c4e8a9d4e1fb6c72d5e8f9a0b1c",
    "recipientId": "recipient_7d2e4f0a9b1c4d8e",
    "address": "ada@example.com",
    "providerTime": "2026-11-08T12:00:04.000Z",
    "possibleDuplicate": false
  }
}

possibleDuplicate is true when the email may have been sent twice, after an unclear submission. Events from a test key also have "mode": "test". Newsletter emails add "purpose": "marketing" and the broadcastId, which is null for an automation email.

Opens and clicks

With open and click tracking on, two more events report engagement with email you send from your app. They are about the whole email, not one recipient, because all its recipients get the same copy, so data has no recipient.

EventWhen it is sent
email.openedThe email was opened for the first time.
email.clickedA link in the email was clicked for the first time. Each link sends its own event, with the link in url.

Later opens and clicks don't send events. Read the counts from GET /v1/emails/:id.

{
  "id": "customer_event_msg_3f2b1c4e8a9d4e1fb6c72d5e8f9a0b1c_clicked_5d41402abc4b2a76b9719d911017c592",
  "type": "email.clicked",
  "createdAt": "2026-11-08T12:03:10.000Z",
  "data": {
    "version": 1,
    "type": "email.clicked",
    "messageId": "msg_3f2b1c4e8a9d4e1fb6c72d5e8f9a0b1c",
    "url": "https://acme.com/orders/1042",
    "occurredAt": "2026-11-08T12:03:09.000Z"
  }
}

email.opened has the same fields without url. A security scanner or a mail app's privacy feature can send these events without a person, so treat them as signals, not proof that someone read the email.

Verify the signature before parsing JSON

The ternwire-signature header contains t=TIMESTAMP,v1=HEX_DIGEST. Compute HMAC-SHA256 with the signing secret over the UTF-8 timestamp, a period, and the raw request body bytes. Compare the digests in constant time and reject malformed headers.

signed_bytes = utf8(timestamp + ".") + raw_request_body
expected_digest = HMAC_SHA256(signing_secret, signed_bytes)
accept only if the digest matches and the timestamp is within 300 seconds

Every SDK ships a helper that does this for you:

import { verifyTernwireWebhook } from "ternwire/verify";

const valid = verifyTernwireWebhook(signatureHeader, rawBodyBytes, signingSecret);

Do not reserialize JSON before checking it, because whitespace changes alter the signed bytes. Reject timestamps more than 300 seconds in the past or future and keep your server clock synchronized.

A complete endpoint reads the raw body, checks the signature, records the event once, and answers 200:

import express from "express";
import { verifyTernwireWebhook } from "ternwire/verify";

const app = express();

app.post("/webhooks/ternwire", express.raw({ type: "application/json" }), async (req, res) => {
  const header = req.get("ternwire-signature") ?? "";
  if (!verifyTernwireWebhook(header, req.body, process.env.TERNWIRE_WEBHOOK_SECRET)) {
    return res.status(400).send("Invalid signature");
  }
  const event = JSON.parse(req.body.toString("utf8"));
  // Save the event under event.id, skipping one you already have, then handle it.
  await saveEventOnce(event);
  res.sendStatus(200);
});

Acknowledge only after durable handling

After verification, parse and validate the event. Use the signed body's event id as a deduplication key. In one durable operation, record the event and enqueue or apply your business action. Return a 2xx response for an already processed event as well as a newly recorded one.

Return success only after that durable step, not immediately on receipt. The endpoint timeout is 10 seconds, so move slow work to your own queue. The event envelope includes type, createdAt, and data. Use its message and recipient IDs to connect it to your records.

Retries, inspection, and replay

Ternwire makes up to 9 automatic attempts, including the initial request. Retry delays in minutes are 1, 5, 15, 60, 240, 720, 1440, 1440. Non-2xx responses, timeouts, and network failures can trigger another attempt.

When every delivery to an endpoint fails for a while, 20 in a row over at least 5 minutes, Ternwire pauses it and the Webhooks page shows it as Paused after failures. Its events wait without using up their retries. Ternwire sends one waiting event as a test after 1 minute, then at growing intervals up to once an hour, and only that test uses one of its retries. The first success resumes the endpoint and sends everything that waited. Disabling and enabling the endpoint resumes it at once. Events are kept for 30 days, so an endpoint paused longer loses the oldest ones.

Inspect the attempt history under Sent events on the Webhooks page or with GET /v1/webhook-attempts/:attemptId. After you fix a handler, choose Send again on a failed attempt, or request a replay with POST /v1/webhook-attempts/:attemptId/replay. Keep your deduplication records, because a replay can repeat an event your application already applied. Use reserved test recipients to verify this behavior before live sending.