Webhooks
Register endpoints, verify signatures, deduplicate retries, and test deliveries — including offline and from the portal.
Webhooks
The platform delivers events to your backend over HTTPS: connections authorizing, records deleted or corrected, exports becoming ready. Webhooks are how you react without polling.
Register an endpoint
Create an endpoint from Curae Platform
or the API. The URL must be a public https:// host on port 443 — the
dispatcher runs in the cloud and cannot reach localhost or a private IP.
const endpoint = await client.createWebhookEndpoint(
{
url: 'https://your-app.example.com/webhooks/curaeai',
eventTypes: ['records.export_ready', 'connection.revoked'],
},
{ idempotencyKey: 'create-prod-endpoint' },
);
// Your secret-manager adapter; never log the signing secret.
await storeSigningSecret(endpoint.data.id, endpoint.data.signingSecret);The signingSecret is returned in the create response and omitted from
later reads. An idempotent replay can return the original create response.
Store it in your secret manager immediately — it's the value you verify deliveries with.
Verify every delivery
Each request carries:
| Header | Meaning |
|---|---|
CuraeAI-Signature | t=<unix_seconds>,v1=<hex_hmac> |
CuraeAI-Timestamp | signing time (unix seconds) |
CuraeAI-Event-Id | stable event id — your dedupe key (constant across retries) |
CuraeAI-Event-Type | e.g. records.export_ready |
The HMAC is HMAC-SHA256(signingSecret, "<t>.<rawBody>"). The canonical
receiver follows four rules in order:
import {
verifyWebhookSignature,
WebhookSignatureError,
parsePlatformWebhookEvent,
PlatformWebhookParseError,
} from '@curaeai/platform-sdk';
// 1. Read the RAW body — the signature is over the exact bytes sent.
const rawBody = await readRawBody(req);
// 2. Verify BEFORE parsing. Reject a bad signature with 400.
try {
await verifyWebhookSignature({
rawBody,
signatureHeader: req.headers['curaeai-signature'],
signingSecret,
});
} catch (e) {
if (e instanceof WebhookSignatureError) return reply(400);
throw e;
}
let event;
try {
event = parsePlatformWebhookEvent(rawBody); // typed union
} catch (e) {
if (e instanceof PlatformWebhookParseError) return reply(400);
throw e;
}
// 3. Atomically deduplicate and persist a job before acknowledging.
// Your durable inbox adapter uses event.eventId as a UNIQUE key and stores
// the event for a background worker. A duplicate is a successful no-op.
// A storage failure must reach your handler's 5xx response path.
await enqueueOnce(event);
// 4. Acknowledge fast (2xx); a worker processes the persisted job.
return reply(200);parsePlatformWebhookEvent validates the envelope and known event type; it
does not validate each event's data fields. Validate the payload against the
event contract before your worker uses it.
Persist the event and its deduplication key together. Marking an event as
processed before its work is durable can lose it if the process crashes after
returning 2xx. The inbox worker must retry failed jobs and make its own side
effects idempotent.
verifyWebhookSignature uses Web Crypto (Node 20+ and edge runtimes), with
a 5-minute replay tolerance, and accepts any v1= segment so a
delivery sent during a signing-secret rotation still verifies.
Retries
The current dispatcher retries network failures and every non-2xx HTTP
response, including 4xx, until its attempt budget is exhausted. Reject
bad signatures with 400; do not acknowledge an untrusted event to suppress
retries. Return 5xx when you cannot durably accept a valid event.
Because retries reuse the same CuraeAI-Event-Id, your
dedupe gate (a durable UNIQUE index in production) makes reprocessing a
no-op.
Event catalog
The SDK ships a discriminated union for every event — narrow on
event.eventType for exhaustive, type-safe handling.
connection.authorized·connection.reconnected·connection.expired·connection.action_required·connection.revokedrecords.export_queued·records.export_ready·records.export_failed·records.export_expiredrecords.deleted— records your app received through the connection were deleted at the person's request;data.deletedRecordsnames each by FHIR type and id, and you must delete every copy you holdrecords.updated— records your app received through the connection were corrected by CuraeAI (re-derived from the stored source data under a new version of how CuraeAI reads it);data.updatedRecordsnames each by FHIR type and id — only records your app was actually served — and you should re-read each one to replace your copy. A large correction arrives as several eventsentry.initiated·entry.completed·entry.limited_provisioned·entry.transferred·entry.foldedconsolidation.completed·consolidation.reversed·consolidation.charts_strandeduser.graduated
Every event is about your own app: its connections, exports, Curae Connect sessions and the accounts behind them. No event names a person's record content or a hospital.
entry.transferred carries a count only: data.connectionCount, how many
hospital connections the person already holds — never which. It is sent only
when the person's handoff authorized a connection. When the transfer came from
a fresh hospital sign-in, connectionCount is 1 and data also carries the
lineage sourceLimitedUserId, survivingUserId and consolidationId.
consolidation.charts_stranded carries counts only — how many hospital
records did not follow the person across a merge (or back across its undo),
and at how many hospitals. It never names a hospital or a record. A stranded
record is one the surviving account already had a chart for at that hospital,
already held a link to (as a guardian or caregiver), or had previously
disowned; its data is not moved and is erased with the absorbed account once
the 24-hour undo window closes. There is nothing for the person to reconnect —
the record they already hold at that hospital is the one Curae keeps — so
render it as information ("N records from the merged account were not carried
over and will be removed"), not as an instruction.
Deletion events are always delivered
connection.revoked, connection.expired and records.deleted each start your
app's duty to delete what it received: a person ended a connection, a
connection expired, or a person deleted records. The Developer Agreement
(§4.2) makes the two connection events deletion triggers. Your app cannot opt
out of them:
- They need no subscription. Every active endpoint of your app receives
them, whatever event types it subscribes to. An endpoint may subscribe to
nothing (
"eventTypes": []): a deletion-only endpoint, which receives these three and no other event. - They are sent whatever the status of your app's Live Access, and
records.deletedis sent for a connection in any status, including one already revoked or expired. - If your app has no active endpoint, or a delivery to one is lost — the
endpoint was disabled, suspended or deleted before the attempt, or every
retry failed, or the last retry was held while your workspace was
suspended — the event is emailed to your account's contact email address
instead, once per event, with the webhook body attached as JSON. Handle it
as you would the delivery, deduplicating on its
eventId. A delivery that succeeds on a retry is not emailed. - In Curae Platform they are shown ticked and cannot be unticked, and you can send any of them as a test event to any endpoint.
Every other event reaches only the endpoints subscribed to it.
Test deliveries
Three ways, from fastest to most realistic:
- Offline —
buildSignedWebhookRequest()produces the production envelope and signing format. POST it at your receiver in a test or from a script. No tunnel, no platform connection. - From the portal — each endpoint has a Send test event button and a per-delivery Resend, with full request/response delivery logs.
- Real — register a public endpoint and exercise the live flow.
The empty data below is a signature-test fixture, not a complete
records.export_ready payload. Validate real events before processing them.
import { buildSignedWebhookRequest } from '@curaeai/platform-sdk';
const { body, headers } = await buildSignedWebhookRequest({
signingSecret,
event: {
eventType: 'records.export_ready',
eventId: crypto.randomUUID(),
data: {},
},
});
await fetch('http://localhost:3001/webhooks/curaeai', {
method: 'POST',
body,
headers,
});Next
- API conventions — errors, idempotency, versioning.
- API reference — the
/api/platform/v1/webhook-endpointscontract.