What are Server-Sent Events:
Server-Sent Events are a Rest API driven event-based subscription flow. The GET requests supported by the device have been extended to support this way of working. Allowing Rest API users to stay up to date with the latest state of any resource.
When is it available:
Version 2.12.0.12 or higher.
How to use Server-Sent Events:
Please refer to the rest API documentation on https://<baseunit-ip-address>:4003/api-docs/v2
Subscribing to an endpoint happens mostly just like executing a GET call to the device. The only difference, the ‘accept’ header must be set to ‘text/event-stream’ mime-type. With this mime-type, the base unit will not close the request upon responding.
The connection will remain open for the base unit to send updates on the resource whenever it is changed/updated. To prevent the closure of the connection because of inactivity, there will be an update every 90 seconds regardless of if there was a change to the resource.
The response/update data looks as follows: “data: {resource-JSON}”
Example:
A Server-Sent Events GET request for the button status using the curl command line application:
curl.exe -X "GET" "https://<baseunit-ip-address>:4003/v2/configuration/buttons" -H "accept: text/event-stream" --user "<username:password>" -k
The response:
data: [{ "id": 1, "connected": false, "connectionCount": 11, "firmwareVersion": "04.13.00", "ipAddress": "192.168.2.35", "lastConnected": "2022-05-11T14:41:49", "lastPaired": "2022-05-11T14:39:41", "macAddress": "08:3A:88:21:45:F0", "serialNumber": "1860097996", "status": "Ok"}]