Examples of the Subscribe Call
Use these templates to build subscribe requests for common scenarios.
These assume you have already established the WebSocket, sent the
connection_init, and received the connection_ack.
Notes:
- Make
idunique for the lifetime of the stream (until you sendcompleteand the server closes). - Include
primaryKeyin the selection set; it can be used to orchestrate a GET for the current resource state. - Persist
metadata.offset(string) andmetadata.uniqueEventIdfor replay, idempotency, and logging. - Streaming does not support requesting specific Business Data Elements in the subscribe request. You either request `detail` or you do not request it; element-level inclusion is determined by the BE template, and `delta=true` removes unchanged elements.
Baseline: chainCode Only
{
"id": "<id>",
"type": "subscribe",
"payload": {
"variables": {
"input": {
"chainCode": "<Chain_Code>"
}
},
"extensions": {},
"operationName": null,
"query": "subscription { newEvent(input: { chainCode: \"<Chain_Code>\" }) { metadata { offset uniqueEventId } moduleName eventName primaryKey detail { oldValue newValue elementName } } }"
}
}
Delta Mode (delta: true)
detail to reduce payload size and
increase throughput.{
"id": "<id>",
"type": "subscribe",
"payload": {
"variables": {
"input": {
"chainCode": "<Chain_Code>"
}
},
"extensions": {},
"operationName": null,
"query": "subscription { newEvent(input: { chainCode: \"<Chain_Code>\" delta: true }) { metadata { offset uniqueEventId } moduleName eventName primaryKey detail { oldValue newValue elementName } } }"
}
}
Replay from Saved Offset
offset after a
disconnect.{
"id": "<id>",
"type": "subscribe",
"payload": {
"variables": {
"input": {
"chainCode": "<Chain_Code>"
}
},
"extensions": {},
"operationName": null,
"query": "subscription { newEvent(input: { chainCode: \"<Chain_Code>\" offset: \"<offset>\" }) { metadata { offset uniqueEventId } moduleName eventName primaryKey detail { oldValue newValue elementName } } }"
}
}{
"id": "<id>",
"type": "subscribe",
"payload": {
"variables": {
"input": {
"chainCode": "<Chain_Code>"
}
},
"extensions": {},
"operationName": null,
"query": "subscription { newEvent(input: { chainCode: \"<Chain_Code>\" offset: \"<offset>\" delta: true }) { metadata { offset uniqueEventId } moduleName eventName primaryKey detail { oldValue newValue elementName } } }"
}
}
Latest Only (offsetType: "highest")
{
"id": "<id>",
"type": "subscribe",
"payload": {
"variables": {
"input": {
"chainCode": "<Chain_Code>"
}
},
"extensions": {},
"operationName": null,
"query": "subscription { newEvent(input: { chainCode: \"<Chain_Code>\" offsetType: \"highest\" }) { metadata { offset uniqueEventId } moduleName eventName primaryKey detail { oldValue newValue elementName } } }"
}
}
{
"id": "<id>",
"type": "subscribe",
"payload": {
"variables": {
"input": {
"chainCode": "<Chain_Code>"
}
},
"extensions": {},
"operationName": null,
"query": "subscription { newEvent(input: { chainCode: \"<Chain_Code>\" offsetType: \"highest\" delta: true }) { metadata { offset uniqueEventId } moduleName eventName primaryKey detail { oldValue newValue elementName } } }"
}
}No Detail Array (orchestrate via REST)
primaryKey to fetch the
latest resource state via REST. Omits the detail array to reduce
bandwidth.{
"id": "<id>",
"type": "subscribe",
"payload": {
"variables": {
"input": {
"chainCode": "<Chain_Code>"
}
},
"extensions": {},
"operationName": null,
"query": "subscription { newEvent(input: { chainCode: \"<Chain_Code>\" }) { metadata { offset uniqueEventId } moduleName eventName primaryKey } }"
}
}Filter by hotelCode
hotelCode filter in the input to target a specific
property.
Note:
Some events do not include ahotelCode (especially profiles when profile sharing is enabled), so you
may receive events with hotelId: null even when
filtering.
{
"id": "<id>",
"type": "subscribe",
"payload": {
"variables": {
"input": {
"chainCode": "<Chain_Code>",
"hotelCode": "<Hotel_Code>"
}
},
"extensions": {},
"operationName": null,
"query": "subscription { newEvent(input: { chainCode: \"<Chain_Code>\" hotelCode: \"<Hotel_Code>\" }) { metadata { offset uniqueEventId } moduleName eventName primaryKey detail { oldValue newValue elementName } } }"
}
}Selecting Fields and Best Practices
- Keep the selection set narrow. Request only fields you will use; include
metadata.offset,metadata.uniqueEventId,eventName,primaryKey, and any requireddetailelements. - Consider
delta: trueto reduce bandwidth and CPU. - Do not include the
detailarray if you plan to orchestrate via REST usingprimaryKey; be mindful of REST rate limits. - Treat payloads as sensitive; avoid logging PII. Keep total headers under 8 KB.
ID Lifecycle
Use a single GUID value for id per active subscription and keep it
constant throughout the subscription lifecycle.
Generate a GUID for id after connection_init. Use the
same id in the subscribe request, match it on server
next messages, and send it again in the complete
request.
Oracle recommends using a GUID because it avoids collisions and makes troubleshooting faster. If you contact Oracle Support, provide the GUID used for the subscription, the application key, chain code, approximate timestamp, and any offset or close code observed.
- Generate a unique
idafterconnection_init. Use the sameidin thesubscriberequest. - The server will tag all
nextmessages for that stream with the sameid; route handling by matching theid. - When finishing, send
completewith the sameid, then wait for the server to close the stream. Do not reuse theiduntil the stream is fully closed. - Reusing an
idfor multiple active operations or sending duplicate operation ids can result in errors (for example, 4409).