Notideus
Tutorials

Webhooks

Register an HTTPS endpoint, verify signed deliveries and inspect the delivery log.

Notideus calls your server when things happen: an email is sent, delivered, bounces; a broadcast finishes; inbound mail arrives. This walkthrough registers an endpoint, verifies the signature on a real delivery and reads the delivery log — management through the official SDK, the receiver in plain Node.js.

npm install notideus
export NT_KEY="nt_live_…"

Prerequisites

  • An HTTPS endpoint you control — plain http, private and loopback URLs are rejected at registration.
  • An API key with the webhooks:read and webhooks:write scopes (a session token works too — management is dual-auth).

Create an endpoint

  1. In the dashboard, open Webhooks → Add endpoint.
  2. Give it a name, paste your URL and pick the events to subscribe to.

Or with the API:

import { Notideus } from 'notideus';

const notideus = new Notideus(process.env.NT_KEY);

const { endpoint, secret } = await notideus.webhooks.create({
  name: 'docs-capture',
  url: 'https://hooks.example.com/notideus',
  events: ['email.sent', 'email.delivered', 'inbound.received']
});

console.log(endpoint.id, secret);

Returns 201 Created with the endpoint and its signing secret:

{
  "endpoint": {
    "id": "01a139b1-1229-78dd-ab26-3724f3e055dc",
    "name": "docs-capture",
    "url": "https://hooks.example.com/notideus",
    "secret_prefix": "whsec_mrXp",
    "events": ["email.sent", "email.delivered", "inbound.received"],
    "status": "active",
    "created_at": "2026-10-14T09:14:28.26542Z",
    "updated_at": "2026-10-14T09:14:28.26542Z"
  },
  "secret": "whsec_mrXpwwEYDk3lmwL93ArKsByIxe6gOpOa"
}
secret (whsec_…) is shown exactly once — put it in your environment now (the receiver below reads NOTIDEUS_WEBHOOK_SECRET). From then on the API keeps only secret_prefix, a display prefix; rotate the secret from the dashboard or POST /v1/webhooks/:id/rotate-secret if it leaks.

The event catalog

Ten events ship today — the descriptions are verbatim from the catalog endpoint:

EventDescription
email.sentAn email was handed off to the provider (status became sent).
email.deliveredThe provider confirmed delivery to the recipient's mail server.
email.bouncedThe email bounced (provider bounce or permanent send failure).
email.complainedThe recipient marked the email as spam (feedback loop).
email.openedThe recipient opened the email (tracking pixel).
email.clickedThe recipient clicked a tracked link.
broadcast.startedA broadcast began sending.
broadcast.completedA broadcast finished sending (all recipients processed).
broadcast.failedA broadcast failed permanently.
inbound.receivedAn inbound email was received, parsed and stored in the inbox.

GET /v1/webhooks/meta/events returns each entry with its type, description and a sample payload — the same catalog drives the dashboard event picker, and await notideus.webhooks.events() returns it typed.

Receive and verify an event

Each delivery is an HTTP POST of a JSON envelope to your url. Three headers ride along:

  • X-Notideus-Signature — t=<unix>,v1=<hmac-sha256 hex>: an HMAC-SHA256 of the <t>.<body> bytes, keyed with the endpoint secret. Tolerate ±5 minutes of clock drift on t.
  • X-Notideus-Event — the event name, mirroring the envelope's event.
  • X-Notideus-Delivery — the envelope's id, for dedupe.

Ack with any 2xx. A complete minimal receiver — standard library only, no framework:

import { createServer } from 'node:http';
import { createHmac, timingSafeEqual } from 'node:crypto';

const secret = process.env.NOTIDEUS_WEBHOOK_SECRET!; // "whsec_…"

function verifySignature(rawBody: string, signature: string): boolean {
  const parts = Object.fromEntries(
    signature.split(',').map((kv) => kv.split('=') as [string, string])
  );
  if (!parts.t || !parts.v1) return false;
  const ts = Number(parts.t);
  if (!Number.isFinite(ts) || Math.abs(Date.now() / 1000 - ts) > 300) return false; // ±5 min tolerance

  const expected = createHmac('sha256', secret)
    .update(`${parts.t}.${rawBody}`)
    .digest('hex');

  const received = Buffer.from(parts.v1, 'hex');
  const computed = Buffer.from(expected, 'hex');
  if (received.length !== computed.length) return false; // timingSafeEqual needs equal lengths
  return timingSafeEqual(received, computed);
}

const server = createServer((req, res) => {
  const chunks: Buffer[] = [];
  req.on('data', (chunk: Buffer) => chunks.push(chunk));
  req.on('end', () => {
    const rawBody = Buffer.concat(chunks).toString('utf8');

    if (!verifySignature(rawBody, req.headers['x-notideus-signature'] ?? '')) {
      res.writeHead(400).end('invalid signature');
      return;
    }

    res.writeHead(200).end('ok'); // ack, then handle — see "Retries and idempotency"

    try {
      const delivery = JSON.parse(rawBody);
      console.log(delivery.event, delivery.id, delivery.data);
    } catch {
      // validly signed but not JSON — log for inspection, the ack already went out
    }
  });
});

server.listen(3000);

The envelope carries event (the event type), id (the delivery id — the same value as X-Notideus-Delivery; dedupe on it), created_at (when the event fired) and data (the email row for email.* events, the inbound message for inbound.received).

Verify against the raw body as received — parsing the payload to an object and re-serializing it changes bytes and breaks the HMAC, so the signature check always runs on the exact string that arrived.

Retries and idempotency

Deliveries are at-least-once. Ack with any 2xx and the delivery is success; anything else retries with backoff — 5 retries over ~15 minutes — after which the delivery is failed. A failed delivery is replayable with POST /v1/webhook-deliveries/:id/redeliver.

Because a retry can arrive twice, dedupe on the delivery id (or the X-Notideus-Delivery header) — keep a store of seen ids and ack duplicates again. The handler must also be idempotent: a redelivered email.sent is the same fact twice, not two sends.

Inspect the delivery log

Every delivery lands in the per-endpoint log — GET /v1/webhook-deliveries, newest first, filterable by endpoint_id, event_type and status:

const page = await notideus.webhooks.deliveries.list({
  endpoint_id: '01a139b1-e35e-773a-a8ee-9570dfdf6e89'
});

Returns 200 OK with the page:

{
  "data": [
    {
      "id": "01a139b2-6ffb-74dd-aca4-93cf118aaed0",
      "endpoint_id": "01a139b1-e35e-773a-a8ee-9570dfdf6e89",
      "event_type": "email.sent",
      "payload": {
        "id": "01a139b2-6e0b-7358-81ee-4bfddaf655e9",
        "to": ["jane@example.com"],
        "from": "Docs Capture <noreply@mail.notideus.dev>",
        "tags": [],
        "detail": "",
        "status": "sent",
        "subject": "Webhook delivery capture",
        "created_at": "2026-10-14T09:15:57.313136Z"
      },
      "status": "success",
      "attempts": 1,
      "last_status_code": 200,
      "last_error": null,
      "delivered_at": "2026-10-14T09:15:58.337796Z",
      "created_at": "2026-10-14T09:15:57.819255Z"
    }
  ],
  "next_cursor": ""
}

attempts counts the HTTP tries so far, last_status_code is the last response your server gave (here 200 on the first try) and delivered_at is when it succeeded. For the per-try detail — one row per HTTP attempt, with duration — fetch the delivery by id: GET /v1/webhook-deliveries/:id (notideus.webhooks.deliveries.get(id)).

Don't wait for live traffic to test the wiring: POST /v1/webhooks/:id/test (await notideus.webhooks.test(id, 'email.sent')) queues a test delivery built from the catalog and pushes it to your endpoint for real.

What's next

Copyright © 2026