Subscriptions
OctoFHIR implements topic-based subscriptions: a SubscriptionTopic describes which changes
can be subscribed to, and a Subscription asks for notifications about one topic on one
channel. Both are ordinary FHIR resources; R5 resources and the R4/R4B
Subscriptions Backport shape are accepted.
Topics
Section titled “Topics”A topic names the resource types and interactions that trigger notifications:
{ "resourceType": "SubscriptionTopic", "url": "http://example.org/topics/patient-change", "status": "active", "title": "Patient changes", "resourceTrigger": [ { "resource": "Patient", "supportedInteraction": ["create", "update"] } ]}Only active topics are matched. Creating or changing a topic takes effect immediately; no
restart is needed.
Subscribing
Section titled “Subscribing”Create the subscription with status requested and point it at the topic URL (topic in
R5, criteria in the backport):
{ "resourceType": "Subscription", "status": "requested", "reason": "Sync patients to the CRM", "criteria": "http://example.org/topics/patient-change", "channel": { "type": "rest-hook", "endpoint": "https://crm.example.org/fhir-hook", "payload": "application/fhir+json" }}A subscription the server cannot serve is refused with 422 and the reason, when it is created
or updated as requested or active:
- the topic URL matches no active topic;
- the channel is one this server can’t deliver to (see below), or a rest-hook endpoint is not an http(s) URL the outbound policy allows;
- the payload type is not
application/fhir+json(orapplication/json): the server writes JSON only; - the payload content is not
empty,id-onlyorfull-resource; - a filter is for a resource type the topic has no events for, or its key is neither a filter of the topic nor a search parameter of that type.
Otherwise the subscription becomes active right after the write, and a rest-hook subscriber first
receives a handshake notification. Should something change before it is activated (a topic
retired in between), it goes to error with the reason in Subscription.error.
To turn a subscription off, set its status to off. Setting it back to requested asks the
server to check and activate it again (and re-sends the handshake).
Channels
Section titled “Channels”| Channel | Support |
|---|---|
rest-hook |
HTTP POST of a subscription-notification Bundle to endpoint, with the subscription’s custom headers. |
websocket |
Connect to GET /fhir/Subscription/{id}/$events with a WebSocket upgrade; the server sends a handshake, heartbeats every heartbeatPeriod seconds and notifications. |
email |
Sent to the mailto: endpoint through the provider in [subscriptions.email] (SMTP or SendGrid). Without a provider it is refused. |
message |
Not supported; refused. |
Filters
Section titled “Filters”A subscription narrows a topic with filters: filterBy in R5, the backport-filter-criteria
extension on criteria in the backport (Encounter?patient=Patient/123, several parameters joined
with &). A key is a filter the topic defines (canFilterBy) or a search parameter of the
resource type, and values compare as in FHIR search: tokens by system|code, references by
Type/id or id, strings case-insensitively from the start (:exact, :contains), dates, numbers
and quantities with eq, ne, gt, lt, ge, le, and :not, :text, :missing. A value with
commas matches any of them. The same matching applies to a topic’s queryCriteria.
R4: the Backport form
Section titled “R4: the Backport form”On an R4 server everything follows the
Subscriptions Backport, since R4 has no
SubscriptionStatus:
| What | R4 form |
|---|---|
| Status in a notification | A Parameters (backport-subscription-status-r4), first in a Bundle of type history |
$status |
A Bundle of such Parameters |
| Payload content | The backport-payload-content extension on channel._payload: empty, id-only or full-resource |
| Heartbeat | The backport-heartbeat-period extension on channel, in seconds |
| Filters | backport-filter-criteria extensions on criteria: Encounter?patient=Patient/123 |
| Topics | Listed on the Subscription resource of the CapabilityStatement (capabilitystatement-subscriptiontopic-canonical) |
A Subscription with an extension of another FHIR version (http://hl7.org/fhir/5.0/…) is refused
with 422: the backport describes those elements itself. R4B and later use SubscriptionStatus.
A handshake is sent while the subscription is still requested. Every event names its focus;
id-only leaves the resource out and empty sends the status alone. A rest-hook subscription with a
heartbeat period gets a heartbeat whenever nothing was sent for that long.
Delivery and Retries
Section titled “Delivery and Retries”Notifications are queued and delivered in the background. A failed delivery is retried with exponential backoff (1, 2, 4, 8 minutes); after five attempts the event is marked failed and counted as an error for the subscription.
Status
Section titled “Status”$status reports the subscription’s state, how many events it has produced and the last
delivery error, if any:
GET /fhir/Subscription/{id}/$status{ "resourceType": "SubscriptionStatus", "status": "active", "type": "query-status", "eventsSinceSubscriptionStart": "42", "subscription": { "reference": "Subscription/{id}" }, "topic": "http://example.org/topics/patient-change", "error": [{ "text": "error sending request for url (https://crm.example.org/fhir-hook)" }]}Event History
Section titled “Event History”A subscriber that missed notifications can ask which changes it missed. A plain GET on
$events (no WebSocket upgrade) returns a history Bundle whose SubscriptionStatus lists past
notifications, oldest first, at most 100 per call:
GET /fhir/Subscription/{id}/$events?eventsSinceNumber=40{ "resourceType": "Bundle", "type": "history", "entry": [{ "resource": { "resourceType": "SubscriptionStatus", "type": "query-event", "eventsSinceSubscriptionStart": "42", "notificationEvent": [ { "eventNumber": "41", "timestamp": "2026-10-31T20:11:02Z", "focus": { "reference": "Patient/123" } }, { "eventNumber": "42", "timestamp": "2026-10-31T20:14:40Z", "focus": { "reference": "Patient/456" } } ] } }]}eventsUntilNumber bounds the range from above.
Delivery Log and Test Notifications
Section titled “Delivery Log and Test Notifications”Two console endpoints help when notifications don’t arrive:
# Recent notifications (newest first) with the latest delivery attempt of eachGET /api/subscriptions/{id}/events?limit=50
# Queue a heartbeat to check the channel end to end (active subscriptions only)POST /api/subscriptions/{id}/pingEach event in the log carries its type (handshake, heartbeat, event-notification), the
focus resource, the delivery status (pending, delivered, failed, …), the number of
attempts, the HTTP status and response time of the last attempt, its error and the next retry
time. The web console’s Subscriptions page shows the same data live and has a
Send test button.