Notifications API
Subscribe to live change events for Records and Object Types in your tenant.
The Notifications API streams change events from your tenant as they happen. Use it to keep a user interface, dashboard, or cache current without polling. For example, a backend service can subscribe to an Object Type and update a live dashboard when its Records change.
Events are live only. The API does not store them, so a client receives only the events that occur while it is connected. To read or change data, use the Native Object API.
The CLI's ctxl logs --follow command also uses this API to show new log messages as they arrive.
What you can do
- Receive an event when a Record of an Object Type is created, updated, deleted, or rolled back.
- Narrow a subscription to one Record or one event action, such as
update. - Receive an event when an Object Type definition is created, changed, or deleted.
The reference also lists POST /events, which publishes events. Contextual services use it to publish the events described here.
Base URL and reference
- API base URL:
https://notifications.<tenant-id>.my.contextual.io/api/v1 - Swagger reference: Notifications API reference
- Raw OpenAPI: openapi.json
Replace <tenant-id> with the tenant ID from your Tenant Workspace URL. On the API base URL, the hostname identifies your tenant, so the x-org-id header is optional. If you send it, its value must match the hostname.
The OpenAPI document uses the relative server /api/v1. When you import it into an API client or AI tool, set the server to the API base URL.
Authentication and permissions
Send an access token in the Authorization: Bearer <access-token> header. For credential types, token audiences, and tenant context, see Authentication and Permissions.
The token needs read permission for the events you want. The API delivers only the events that the token can read and leaves out the rest without an error. If a stream shows only heartbeats while matching changes occur, check the read permissions.
| Events | Subscription parameters | Required permission |
|---|---|---|
| Record changes for an Object Type | namespace=native-object and module=<type-id> |
Object data & action execution → Read for that Object Type |
| Object Type definition changes | namespace=contextual and module=native-objects |
Service components → Object Types → Read |
The permission names match the labels on an API Key's Permissions tab. If you use an API Key, set them there.
A browser's native EventSource cannot send the Authorization header, and the API does not accept a token in the URL. A fetch-based server-sent events (SSE) client can send the header, and the API accepts cross-origin requests that include it. Never put a Client Secret in browser code. To show live updates without giving a browser an access token, subscribe from your server and forward the updates to your page.
Request and response details
- Subscribe with
GET /events. Thenamespaceparameter is required:native-objectorcontextual. Addmodule,id, oractionto narrow the subscription. If you omit one of these parameters, the subscription matches every value. - For Record events,
moduleis the Object Type ID used in its Native Object API path, andidis the Record's primary key value. Record changes use the actionscreate,update,delete, androllback. - A subscription without
actioncan also receive other actions, such as log activity for a Record or a Record count for an Object Type. Checkactionbefore you act on an event. - The response has content type
text/event-streamand stays open. Each event is adata:line with one JSON object. The object containsorgId,namespace,module,id,action, anddata. The event content is indata.data, anddata.metaDatacan includerequestIdandlogCorrelationId. - For the Record actions
create,update,delete, androllback,data.datais the Record, and Secret properties show<ENCRYPTED>. Other actions carry other content. - About once per second, the API sends an
event: heartbeatmessage with no data. Ignore it. - Delivery is best effort. Events are not replayed and have no IDs to resume from. A large event, or a large batch of events, may not be sent. After you reconnect, read the current state to catch up: Records from the Native Object API, and Object Type definitions from the Native Object Registry API. The stream sets
retry: 10000, so standard SSE clients wait 10 seconds before they reconnect. - Bulk deletions do not send a Record
deleteevent for each Record. Deleting all Records of an Object Type with the Native Object Registry API sends no Recorddeleteevents. Deleting an Object Type sends one Object Typedeleteevent, not one for each of its Records. Deleting one Record with the Native Object API sends a Recorddeleteevent, with the same best-effort delivery as other events. - Reconnect with a valid access token. A request with an expired token returns
401.
Example request
This request subscribes to changes to the Records of one Object Type:
curl --no-buffer "https://notifications.<tenant-id>.my.contextual.io/api/v1/events?namespace=native-object&module=<type-id>" \
--header "Authorization: Bearer <access-token>"
Replace <type-id> with the Object Type ID and <access-token> with your access token. A successful response has status 200 and stays open. It sends a heartbeat about once per second and a data: line for matching events, which can include actions other than Record changes. Press Ctrl+C to close the stream.