Events and webhooks
MarkdownKeep your app up to date when a user connects or disconnects, one of their browsers is attached,
comes online or goes offline, or their site access changes.
Apigami can send these updates to your server as webhooks. You can also read them with
GET /events.
Registering an endpoint
Section titled “Registering an endpoint”Ask your AI assistant to register it with the MCP tool app_webhooks_write:
- Your server’s public HTTPS URL.
- The events to receive, its
types: a type of the table below,<namespace>.*for a whole namespace, or a type your application declares inx-apigami.events, such asmessage.createdormessage.*. Leave them empty to receive all types but the end of your tasks,task.completed(When a task ends). An endpoint hears it only by naming it ortask.*in itstypes. - If you want only some of them, a
filteron their content: dotted paths into the event’sdata, each with the values it may hold.{ "channel": ["discord"] }keeps Discord’s messages alone, and{ "from.handle": ["123456789012345678", "jane@example.com"] }one sender’s on any channel. Every path must be present and equal to one of its values, a text, a number, a boolean or null, never an array;user_refandinstall_refcan’t be filtered on.updatewithfilter: nullremoves it. - The signing secret it returns once: put it in your server’s configuration.
Verify each request’s signature, save its events for processing, and return a 2xx response
within 10 seconds. Apigami retries failed deliveries.
A webhook receives your own application’s events only. To hear the applications under yours, subscribe an action
of yours in x-apigami.subscriptions:
app_webhooks lists those rows apart, under Subscriptions, from your manifest, each with its types, the
applications whose production emits one, and its deliveries, each naming the application that emitted its event.
app_webhooks_write disables or enables one and sends a delivery again; update, delete and test answer 400,
since a deployment writes them.
Event types
Section titled “Event types”| Type | What it means |
|---|---|
extension.online | One of your user's browsers came online |
extension.offline | One of your user's browsers went offline |
extension.attached | Your user attached a browser to their account: your app can reach it |
extension.detached | Your user detached a browser from their account: your app no longer reaches it |
app_user.created | A user connected their account to your app |
app_user.updated | This user's approvals, language or identity changed: a site or a permission was approved, refused or withdrawn, they chose another language, or their name or email changed under identity |
app_user.removed | The user disconnected their account from your app |
subapp_user.accepted | A user accepted your optional sub-app in an app that uses it |
subapp_user.removed | Your optional sub-app no longer serves this user in an app that used it |
stream.opened | The browser opened a live stream you subscribed to |
stream.event | The site pushed an event on a live stream |
stream.closed | A live stream closed: the site ended it, the browser lost it, or the subscription was removed |
app.health.failed | A published version of your service stopped answering its health check |
app.health.recovered | A published version of your service answers its health check again |
task.completed | A task your app queued ended, in its own queue or a sub-app's: succeeded, failed, expired or cancelled, with what its worker answered |
Each event includes an id, a type, a created_at timestamp, an app_id, the user_ref
of the user it concerns and the install_ref of the browser, the same references
POST /connect/token returns. install_ref is null on an
event about the user rather than one browser, such as app_user.updated. app_id is your application on what
reaches your webhooks; on what a subscription of yours receives, it is the application that emitted the event, one
of those under yours, or the application whose queue held the task of a task.completed.
Users, site decisions and browser presence
app_user.created and app_user.updated carry the user’s complete grants list, including
refusals. Each entry has a domain, granted and decided_at. A missing domain hasn’t been
requested; granted: false means access is denied. Approvals belong to the user, so one list
covers all their browsers.
Beside grants, permissions lists the user’s decisions on your emails and your AI, each
{ permission, granted, decided_at }, permission being emails, ai or identity; a permission missing from it
was never decided. Sites never appear in permissions, nor permissions in grants.
app_user.created, app_user.updated and subapp_user.accepted also carry locale, the language the user reads
Apigami in: en, fr, es or de. Write to them in it. For a user who reaches your app only as a sub-app, through an app they connected to,
no event comes when it changes, nor when their name or email does: read them again with
GET /v1/users/{user_ref}.
On app_user.updated, change describes one thing that changed, in one of five shapes: { domain, decision, was_granted }
for a site, { permission, decision, was_granted } for emails or AI, { terms: { app_id, terms_version } }
when the user agreed to the terms and subprocessors of your app or of a sub-app it calls, which has
no decision, { locale } when the user chose another language, locale beside it saying the same, or
{ identity } for identity: "granted", "name" or "email" when the
user granted it or their name or email changed, "withdrawn" when removing an optional sub-app took it back; an
optional sub-app of another group hears them for its own line, with connected_at null and permissions empty. An event
never carries the name nor the email, which go to every application that hears it: read them again with
GET /v1/users/{user_ref}. Branch on the key present, never on domain
alone. A revocation has
decision: "denied" and was_granted: true; a first refusal has was_granted: false.
When a user removes an optional sub-app, each grant only it brought is erased and arrives as that revocation,
the entry gone from grants or permissions: the complete state is authoritative, so replace your copy with it.
A user who disconnects from your app produces app_user.removed; their decisions are kept. If
they connect again, app_user.created includes those decisions. A deleted account sends nothing: read
GET /v1/users/unreached to learn who to erase.
An optional sub-app receives
subapp_user.accepted when a user accepts it under your app, and subapp_user.removed when they leave its
list: they removed it, disconnected from your app, or your app published a version that no longer declares
it optional. Each names your app in root_app_id. What the user approved for it is yours, in your grants
and permissions.
extension.attached tells you a user added a browser your app can now reach, with the name they
gave it and its presence; extension.detached that one left their account. A user detaches a
browser from their account page or, from Apigami 0.15.0, from Apigami’s settings in that browser:
your streams for that user on it close with detached, and the user’s approvals stay, for their
other browsers. The other accounts attached to that browser keep it. The extension.*
events go to every app that reaches the browser’s user: connected to them, or a sub-app an app they connected
to reaches, past no optional sub-app they have not accepted.
Brief connection interruptions don’t produce presence events. A browser that’s gone offline is
announced within about three minutes. For an immediate check, use
GET /v1/users/{user_ref}/installs.
presence_changed_at records the published status change; last_seen_at is a throttled heartbeat.
Neither replaces created_at for ordering events.
The request
Section titled “The request”POST /apigami/webhooks HTTP/1.1Host: hooks.example.comContent-Type: application/jsonUser-Agent: Apigami-Webhooks/1Apigami-Delivery-Attempt: 1Apigami-Signature: t=1789035151,v1=5f8c…[ { "id": "6f1c2d3e-4a5b-4c6d-8e9f-0a1b2c3d4e5f", "type": "app_user.updated", "created_at": "2026-09-10T10:12:31.128Z", "app_id": "2b7f6a41-0c9d-4a3e-9f21-8d5c4b3a2109", "user_ref": "usr_3f9c1a0e7b2d4c58a61e9f0b2d7c4e13", "install_ref": null, "data": { "connected_at": "2026-09-01T08:00:00.000Z", "locale": "fr", "grants": [ { "domain": "acme.com", "granted": false, "decided_at": "2026-09-10T10:12:31.128Z" }, { "domain": "example.com", "granted": true, "decided_at": "2026-09-02T09:30:00.000Z" } ], "change": { "domain": "acme.com", "decision": "denied", "was_granted": true } }, "data_erased_at": null }, { "id": "8a2e4f60-1b3c-4d5e-9f70-2c4d6e8f0a1b", "type": "extension.online", "created_at": "2026-09-10T10:12:33.502Z", "app_id": "2b7f6a41-0c9d-4a3e-9f21-8d5c4b3a2109", "user_ref": "usr_3f9c1a0e7b2d4c58a61e9f0b2d7c4e13", "install_ref": "ins_9d0c7e1f2a3b4c5d6e7f8a9b0c1d2e3f", "data": { "flavor": "standard", "presence_changed_at": "2026-09-10T10:12:33.502Z", "last_seen_at": "2026-09-10T10:12:33.502Z" }, "data_erased_at": null }]The body is always a JSON array of events, even for a single one. A request carries 1 to 100 events and
at most 1 MB; an event larger than that arrives alone. Apigami groups only the events already waiting for
your endpoint, never holds one back to fill a request, and sends them oldest first by (created_at, id).
A 2xx acknowledges every event in the request; any other answer fails all of them, and they are retried
together or alongside newer ones. Apigami-Delivery-Attempt is the highest attempt among them: 1 means
every event is sent for the first time.
app_webhooks shows the delivery status and the first kilobyte of your response body.
A short error message helps you diagnose failed attempts.
Verifying the signature
Section titled “Verifying the signature”Check the Apigami-Signature header using the raw request body and your signing secret.
Do this before parsing JSON. The example below checks the signature and rejects timestamps more
than five minutes from the current time.
Signature verification in JavaScript
import { createHmac, timingSafeEqual } from 'node:crypto'
const TOLERANCE_SECONDS = 5 * 60
// rawBody: the request body exactly as it arrived, as a string. secret: the whsec_… value.export function verifySignature(rawBody, header, secret) { const fields = (header ?? '').split(',').map((field) => field.trim().split('=')) const t = fields.find(([key]) => key === 't')?.[1] const signatures = fields.filter(([key]) => key === 'v1').map(([, value]) => value) if (!t || !/^\d+$/.test(t) || !Number.isSafeInteger(Number(t)) || signatures.length === 0) return false
// Fresh: the attempt is signed with its own time, so a replay stops verifying five minutes later. if (Math.abs(Date.now() / 1000 - Number(t)) > TOLERANCE_SECONDS) return false
const expected = createHmac('sha256', secret).update(`${t}.${rawBody}`).digest() return signatures.some((signature) => { if (!/^[a-f0-9]{64}$/i.test(signature ?? '')) return false const given = Buffer.from(signature, 'hex') return given.length === expected.length && timingSafeEqual(given, expected) })}Read the raw body before a JSON parser changes it. For example, with a text-body middleware:
app.post('/apigami/webhooks', express.text({ type: 'application/json' }), async (req, res) => { if (!verifySignature(req.body, req.get('Apigami-Signature'), process.env.APIGAMI_WEBHOOK_SECRET)) { return res.sendStatus(400) } const events = JSON.parse(req.body) // always an array for (const event of events) await queue.add(event) // Persist to your job queue before acknowledging. res.sendStatus(200)})Use a durable job queue for queue.add and handle failures through your server’s error handler: a failure
answers non-2xx, so the whole request comes back, events already queued included.
Register the raw-body route before any global JSON parser.
The signature is HMAC-SHA256 over `${t}.${rawBody}`, using the full whsec_… secret
as UTF-8. Every retry has a fresh timestamp. If multiple v1 signatures are present,
accept any valid match.
Trying it out
Section titled “Trying it out”Ask for a test with app_webhooks_write. It sends a signed array holding one webhook.test event and shows
your endpoint’s response status and time. Use it to check the signature verification.
Return 200 for test events. They have an empty data object and null user_ref, install_ref and
data_erased_at;
they aren’t retried or included in GET /events.
Delivery and retries
Section titled “Delivery and retries”Process each event once using its id. Delivery order can change during retries:
when updating a user’s or a browser’s state, keep the event with the newest created_at.
Retry schedule and disabled endpoints
A failed delivery gets seven retries after the first attempt: after 1 minute, 5 minutes, 30 minutes, 2 hours, 8 hours, 24 hours and 48 hours from the previous attempt. After eight failed attempts, that delivery stops. Each event keeps its own schedule, so a retried event can arrive in a request with different companions.
Redirects, non-2xx responses and timeouts count as failures. Only public HTTPS endpoints are
accepted; the address is checked before each attempt and redirects aren’t followed.
Each matching endpoint gets its own delivery. types accepts types and namespaces such as app_user.*,
and filter narrows them by content.
After seven days of continuous failures, the endpoint is disabled and pending deliveries fail.
Fix and re-enable it with app_webhooks_write, or update its URL. It resumes with new events;
use GET /events to recover what you missed.
Keep processed event IDs for at least four days to cover the retry window. If you also poll,
deduplicate those events using the same IDs. created_at determines which state is newest,
including for presence events; last_seen_at and presence_changed_at don’t.
Reading the journal: GET /events
Section titled “Reading the journal: GET /events”Events are available for 30 days. Read them with your app’s API key to recover missed deliveries,
or use polling if you don’t have a public webhook URL. Your --staging version’s key reads none: production alone
reads and acknowledges the journal.
An event’s data is kept only until your app has it. Once every endpoint it was sent to has
answered 2xx, or, if your app polls instead of receiving webhooks, once you acknowledge it (below),
Apigami erases its data. Nothing else erases it: reading the journal with since does not. A delivery
still being retried keeps it until that delivery succeeds or gives up, so no endpoint receives an
emptied event. The rest of the event stays for the 30 days, so a later read returns it with
data: null and data_erased_at set to when the content was erased. An event of Apigami’s that no
endpoint received and that you haven’t acknowledged keeps its data for the 30 days. An event your app
emits that none of your endpoints and no subscription above yours receives is stored
already erased: GET /events returns it with data: null from the start.
The end of a task is the exception: task.completed is journaled only when something listens for
it: a webhook of yours that names it or task.* for your own task, or the subscription of the application
that asked for it. With neither, GET /events never returns it.
curl -G https://api.eu.apigami.com/events \ -H "Authorization: Bearer $APIGAMI_API_KEY" \ --data-urlencode "since=2026-09-10T00:00:00Z" \ --data-urlencode "types=app_user.*,extension.offline" \ --data-urlencode "limit=100"Pagination and polling example
| Parameter | |
|---|---|
since |
An ISO timestamp; events strictly after it. Default: 30 days ago. It acknowledges nothing |
cursor |
The next of a previous answer. It encodes a position, not a row, so a cursor kept across the 30-day purge still works. cursor wins over since. Sending it acknowledges the events earlier reads returned up to it, with the same types: their data is erased |
types |
Comma-separated types or <namespace>.*, your own application’s types included, such as message.*. An unknown type matches nothing |
limit |
Default 100, clamped to 1000. A page also stops after the event that brings its data past 4 MiB, so a page of large events holds fewer; the first event always comes |
The answer is { "events": [...], "next": "<cursor>" | null }, oldest first, ordered by
(created_at, id). next names the last event of the page, whether it stopped at limit or at 4 MiB, and is null only when the page is empty. Only your own events come back: the key names the app, and there is no parameter
to name another one. API keys only — a member’s session or a personal access token answers
401 bad client credentials, as on POST /call.
To poll instead of receiving, keep the last next and ask again. Store it only once its page is
handled: the next request sends it back, and that is what tells Apigami it can erase those events’ data.
let cursor = await store.get('apigami:cursor') // null the first time
for (;;) { const query = cursor ? { cursor } : { since: '2026-09-10T00:00:00Z', limit: '100' } const url = `https://api.eu.apigami.com/events?${new URLSearchParams(query)}` const { events, next } = await fetch(url, { headers: { Authorization: `Bearer ${process.env.APIGAMI_API_KEY}` }, }).then((r) => r.json())
for (const event of events) await handle(event) // idempotent, by event.id
// Store the cursor only once the page is handled: a crash then costs a repeat, never a gap. if (next) await store.set('apigami:cursor', (cursor = next)) if (events.length === 0) await sleep(30_000)}Full parameters and shapes: GET /events.