Developer Documentation: openIMIS Subscription API
This document provides a guide for developers to programmatically create and manage resource subscriptions using the openIMIS backend's REST API. All examples use curl, a universal command-line tool for making HTTP requests.
1. Overview & Authentication
The openIMIS Subscription API allows external applications to be notified via a webhook when a specific FHIR resource (e.g., Claim) is created or updated.
All API requests require authentication. The process involves two steps:
Login: Send a
POSTrequest with a username and password to the/loginendpoint to receive a temporary JSON Web Token (JWT).Authenticated Request: Include this JWT as a Bearer Token in the
Authorizationheader of all subsequent API calls.
2. Step-by-Step API Interaction
Step 2.1: Login and Obtain an Auth Token
First, you must authenticate to get a JWT. This token is required for all other API calls.
Endpoint: POST /api/api_fhir_r4/login/
Request:
curl --location 'http://<openimis-endpoint>/api/api_fhir_r4/login/' \
--header 'Content-Type: application/json' \
--data '{
"username": "username",
"password": "password"
}'
Method:
POSTURL: The base URL of your openIMIS instance followed by
/api/api_fhir_r4/login/.Headers:
Content-Type: application/json: Indicates that the request body is in JSON format.
Body: A JSON object containing the
usernameandpasswordfor a valid openIMIS user.
Successful Response (200 OK):
The server will respond with a JSON object containing the token.
{
"token": "<jwt_token>",
"exp": 1751291634
}
Step 2.2: Create a Subscription
To start receiving notifications, you must create a subscription resource on the server.
Endpoint: POST /api/api_fhir_r4/Subscription/
Request:
curl --location 'http://<openimis-endpoint>/api/api_fhir_r4/Subscription/' \
--header "Authorization: Bearer ${BEARER_TOKEN}" \
--header 'Content-Type: application/json' \
--data '{
"resourceType": "Subscription",
"status": "active",
"end": "2029-12-31T23:59:59Z",
"reason": "Notify on new Claims",
"criteria": "Claim",
"channel": {
"type": "rest-hook",
"endpoint": "http://<subscriber-endpoint>/callback",
"header": [
"{\"Content-Type\": \"application/json\", \"Accept\": \"application/json\"}"
]
}
}'
Request Breakdown:
Method:
POSTURL: The base URL followed by
/api/api_fhir_r4/Subscription/.Headers:
Authorization: Bearer <YOUR_TOKEN>: This is mandatory. It proves you have the right to create a subscription.Content-Type: application/json: Specifies the body format.
Body (JSON Payload):
resourceType: Must be"Subscription".status: Must be"active"to start receiving notifications. Other options might include"requested"or"off".end: (Optional, but recommended) An ISO 8601 timestamp for when the subscription should automatically expire.reason: A human-readable string explaining the purpose of this subscription.criteria: (Crucial) A string specifying the FHIR resource to monitor. Examples:"Claim","Patient","Coverage","Insuree".channel: An object describing how notifications should be delivered.type: Must be"rest-hook"for webhook notifications.endpoint: (Crucial) The full, publicly accessible URL where your client application is listening forPOSTrequests. The openIMIS server must be able to reach this URL.For production, this must be a public internet URL (e.g.,
https://api.your-app.com/webhook).
header: An array of strings defining headers to be sent with the webhook notification. The specific format["{\"Key\": \"Value\"}"](a list containing one stringified JSON object) may be required by the backend.
Successful Response (201 Created):
The server will respond with the full subscription resource it just created, including a server-generated id.
{
"resourceType": "Subscription",
"id": "219abbba-ed14-4c35-8ac4-7cfeac0cc9ed", // <-- IMPORTANT ID
"status": "active",
"end": "2029-12-31T23:59:59Z",
"reason": "Notify on new Claims",
"criteria": "Claim",
"channel": {
"type": "rest-hook",
"endpoint": "http://<subscriber-endpoint>/callback",
"header": [
"{\"Content-Type\": \"application/json\", \"Accept\": \"application/json\"}"
]
}
}
Step 2.3: Unsubscribe (Delete a Subscription)
When you no longer wish to receive notifications, you should delete the subscription resource from the server. Based on the backend implementation, this is done via a DELETE request.
Endpoint: DELETE /api/api_fhir_r4/Subscription/{id}/
Request:
# Replace with a fresh token and the ID of the subscription you want to delete.
BEARER_TOKEN="YOUR_BEARER_TOKEN"
SUBSCRIPTION_ID="219abbba-ed14-4c35-8ac4-7cfeac0cc9ed"
curl --location --request DELETE "http://<openimis-endpoint>/api/api_fhir_r4/Subscription/${SUBSCRIPTION_ID}/" \
--header "Authorization: Bearer ${BEARER_TOKEN}"
Request Breakdown:
Method:
DELETEURL: The URL must include the unique
idof the subscription you want to remove.Headers:
Authorization: Bearer <YOUR_TOKEN>: Mandatory for authentication.
Body: A
DELETErequest does not have a body.
Successful Response (204 No Content):
A successful deletion will typically return a 204 No Content status code. This means the operation succeeded, and there is no data to return in the response body.
4. Receiving Webhook Notifications
Once a subscription is active, any creation or update of a resource matching the criteria will cause the openIMIS server to send an HTTP POST request to the endpoint URL you specified.
Method:
POSTHeaders: The headers will include what you defined in the
channel.headerarray (e.g.,Content-Type: application/json).Body: The body will contain a FHIR resource representing the notification event. This often includes a link to the resource that was updated.
Client application at the endpoint URL must be prepared to:
Accept
POSTrequests.Parse the JSON body of the request.
Return a
2xx(e.g.,200 OKor204 No Content) status code promptly to acknowledge receipt. If the server receives a non-2xxstatus, it may retry sending the notification.
4.1. The subscriber will receive following response in a callback url:
{
"resourceType": "ClaimResponse",
"id": "68a42d00-bbc0-4ae3-b842-46ca5a814adc",
"identifier": [
{
"type": {
"coding": [
{
"system": "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/openimis-identifiers",
"code": "UUID"
}
]
},
"value": "68a42d00-bbc0-4ae3-b842-46ca5a814adc"
},
{
"type": {
"coding": [
{
"system": "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/openimis-identifiers",
"code": "Code"
}
]
},
"value": "907"
}
],
"status": "active",
"type": {
"coding": [
{
"system": "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/claim-visit-type",
"code": "O",
"display": "Other"
}
]
},
"use": "claim",
"patient": {
"reference": "Patient/d8393487-c3aa-4d3a-b56f-82f9b3b47a46",
"type": "Patient",
"identifier": {
"type": {
"coding": [
{
"system": "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/openimis-identifiers",
"code": "UUID"
}
]
},
"value": "d8393487-c3aa-4d3a-b56f-82f9b3b47a46"
}
},
"created": "2025-06-30",
"insurer": {
"reference": "openIMIS"
},
"requestor": {
"reference": "Practitioner/53d8bd54-f155-4dec-8564-8045c199dc3c",
"type": "Practitioner",
"identifier": {
"type": {
"coding": [
{
"system": "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/openimis-identifiers",
"code": "UUID"
}
]
},
"value": "53d8bd54-f155-4dec-8564-8045c199dc3c"
}
},
"request": {
"reference": "ClaimV2/68a42d00-bbc0-4ae3-b842-46ca5a814adc",
"type": "ClaimV2",
"identifier": {
"type": {
"coding": [
{
"system": "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/openimis-identifiers",
"code": "UUID"
}
]
},
"value": "68a42d00-bbc0-4ae3-b842-46ca5a814adc"
}
},
"outcome": "complete",
"item": [
{
"extension": [
{
"url": "https://openimis.github.io/openimis_fhir_r4_ig/StructureDefinition/claim-item-reference",
"valueReference": {
"reference": "ActivityDefinition/488d8bcb-5b88-438c-9077-f177f6f32626",
"type": "ActivityDefinition",
"identifier": {
"type": {
"coding": [
{
"system": "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/openimis-identifiers",
"code": "UUID"
}
]
},
"value": "488d8bcb-5b88-438c-9077-f177f6f32626"
},
"display": "A1"
}
}
],
"itemSequence": 1,
"adjudication": [
{
"category": {
"coding": [
{
"system": "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/claim-status",
"code": "1",
"display": "rejected"
}
]
},
"reason": {
"coding": [
{
"system": "https://openimis.github.io/openimis_fhir_r4_ig/CodeSystem/claim-rejection-reasons",
"code": "7",
"display": "FAMILY"
}
]
},
"amount": {
"value": 400,
"currency": "$"
},
"value": 1
}
]
}
]
}
Demo of subscription process using mock application
Mock simulated app
sandbox/mock_claim_subscription at develop · openimis/sandbox
Did you encounter a problem or do you have a suggestion?
Please contact our Service Desk
This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License. https://creativecommons.org/licenses/by-sa/4.0/