ChartnautDocs

Webhooks

Webhooks tell your server that something changed, by type and id. They are hints: delivered at least once, in no set order, and possibly late. Read the object with the API before you act on it.

Add endpoints in the partner portal under Webhooks, up to 5. Each has its own signing secret, which Rotate secret replaces. Send test event there, or GET /webhooks/test, sends a test.ping and answers 202 with its event_id.

Events

Type

data

Read

user.connected

user, external_user_ref

GET /users/{user}

user.disconnected

user, external_user_ref, by: user, partner or admin

GET /users/{user}

user.deleted

user, external_user_ref

Delete what you hold for them

session.ended

user, session, status, and the session's external_ref if it has one

GET /sessions/{session}

rule.breached

user, external_user_ref, session or account, breach, rule_id

the session's or account's breaches

alert.fired

user, external_user_ref, alert, fire

GET /users/{user}/alert-fires

test.ping

nothing

alert.fired is sent only while the user grants alerts:read.

{
  "id": "evt_8f2c1a",
  "type": "session.ended",
  "created_at": "2026-11-17T14:02:11Z",
  "data": { "user": "usr_42", "session": "ses_90211", "status": "breached" }
}

Deduplicate on id. Every delivery also carries Chartnaut-Event-Id and Chartnaut-Event-Type headers. Answer with any 2xx within 10 seconds. Anything else is retried, up to 24 attempts in all, waiting 30 seconds at first and doubling to at most 12 hours between tries: about a week. After that the delivery is marked dead and you can resend it from the portal's webhook log.

An endpoint that fails 25 times in a row over more than an hour is paused: its events wait 3 days and go out when you press Resume. Live endpoints also count against your developer plan; after a downgrade, the ones over the limit pause with the reason over_plan_limit once a 7-day grace ends. Webhooks in the SDK docs explains choosing which to keep.

Check the signature

Every delivery carries Chartnaut-Signature: t=<unix seconds>,v1=<hex>, where v1 is HMAC-SHA256 of t, a full stop and the raw body, keyed with the endpoint's secret. While you rotate a secret the header carries a second v1 signed with the old one: accept either. Refuse anything more than five minutes old.

import crypto from 'node:crypto';

function verify(secret, header, rawBody) {
  const parts = header.split(',').map((p) => p.split('='));
  const t = Number(parts.find(([k]) => k === 't')?.[1]);
  if (!t || Math.abs(Date.now() / 1000 - t) > 300) return false;
  const want = crypto.createHmac('sha256', secret).update(`${t}.${rawBody}`).digest();
  return parts
    .filter(([k]) => k === 'v1')
    .some(([, v]) => {
      const got = Buffer.from(v, 'hex');
      return got.length === want.length && crypto.timingSafeEqual(got, want);
    });
}

Verify the raw bytes you received, before parsing them.