WebSocket

Websockets provides a live stream of data from devices or collections directly through the API. The endpoint is dynamically built based on the collectionId as well as the deviceId if you’re only looking to subscribe to messages from a single device.

Connecting to a WebSocket

With API token

To be able to connect you first need an API Token which can be created in the Span dashboard. The token must be a read-only token due to security and have access to the collection or the device in question. To use the WebSocket endpoint, authenticate with the header X-API-Token and set the value to be your API-token.

X-API-Token: abcdef...hijkg

With login token

Endpoint

Each collection has a websocket in the from resource. Replace {collectionId} with your collection ID and use the following URL:

wss://api.lab5e.com/span/collections/{collectionId}/from

Word of warning

A websocket isn’t suited for production systems, only for testing and demonstration purposes. Use either webhooks or MQTT if you want message buffering.