Websocket Reference
Reference documentation for Ardexa's Websocket API
Overview
Live data from the Ardexa Cloud, pushed over a websocket as it arrives.
The REST API returns records that are already stored, one request at a time. This API keeps a connection open and pushes each record as the cloud receives it, so an integration can follow a workgroup's devices without polling — and can read a large result set as it is read, rather than waiting for one response.
Regions
Ardexa runs clouds in several regions, each on its own subdomain. Connect to the cloud your workgroup belongs to — app.ardexa.com or eur1.ardexa.com. A token issued by one region is not valid on another.
Connecting
The transport is socket.io v4. Connect to the region's host at the path /socket.io-client, passing your API token and the workgroup ID as handshake auth:
import io from "socket.io-client";
const socket = io("https://app.ardexa.com", {
path: "/socket.io-client",
transports: ["websocket"],
auth: {
token: process.env.ARDEXA_TOKEN,
orgName: "my-workgroup",
},
});The token is the same Ardexa API token the REST API uses. A connection is bound to the one workgroup named at handshake, so subscribe on a separate connection per workgroup. A missing, expired or revoked token, or a workgroup the token does not cover, is refused with a connect_error rather than an error on a later event. An expiring token does not renew itself: once it expires the next event you send disconnects the socket, so reconnect with a fresh one.
How an event answers
Most events follow the same shape. You send an event with a requestId you generate; the cloud answers on the same name with :rpc appended, and — where an event produces a series of results rather than one — sends each of those on :reply. Both carry back the requestId, so one connection can have several requests in flight:
An :rpc frame carrying error means the request was refused or failed; the connection stays open either way. The reference below says which events depart from this shape — stream:latest answers on stream:latest:data, and the notifications arrive unsolicited.
Message encoding
Payloads are plain JSON objects in both directions, with one exception: stream:latest:data is CBOR-encoded binary, because it carries the highest message rate. Decode those frames before reading them:
Any event whose payload is not JSON says so in the reference below.
Permissions
Permissions are granted per workgroup when a token is issued, and the same ones govern this API. Every API token carries Read, which is what every event here needs.
Streaming or searching the audit_logs table needs Read audit logs. That permission is not offered when issuing an API token, so treat audit_logs as unavailable to integrations.
A token restricted to a single device group sees only that group's devices — in streams, searches and live feeds alike. No error is returned; the data is simply narrower.
When a subscription fails
Failures come back on the request's own answer — an :rpc frame carrying error, or for stream:latest, a stream:latest:data frame carrying error instead of result. Both carry the requestId you sent. Nothing is thrown, and the connection stays open.
An error is either a plain string or an object with a code and a message, depending on the event. A refusal for want of permission names the permission and the workgroup it was needed in.
Events
Event index
stream:latest
Client → server
Start following a table's records as they arrive.
stream:latest:data
Server → client
Receive the records a subscription produces.
stream:latest:stop
Client → server
Stop a subscription.
search
Client → server
Search a table and receive the records page by page.
search:rpc
Server → client
Receive the search's match count, or the reason it failed.
search:reply
Server → client
Receive each page of matching records.
device:feed
Client → server
Open a live feed on one of a device's streams.
device:feed:rpc
Server → client
Receive the feed's id, or the reason it could not be opened.
device:feed:reply
Server → client
Receive each reading from a live feed.
device:feed:stop
Client → server
Close one live feed.
device:feed:stopAll
Client → server
Close every live feed on this connection.
device:bulkFeed
Client → server
Open one live feed covering many device streams.
device:bulkFeed:rpc
Server → client
Receive the bulk feed's id, or the reason it could not be opened.
device:bulkFeed:reply
Server → client
Receive each reading from a bulk live feed.
device:stateChange
Server → client
A device came online or went offline.
device:new
Server → client
A device was added to a workgroup.
device:metaChange
Server → client
A device reported new metadata.
incident
Server → client
An alert raised an incident, or an incident was resolved.
job
Server → client
A background job changed.
deviceSchedule
Server → client
A device schedule was created or changed state.
deviceSetpoint
Server → client
A device setpoint was created or changed.
Streaming
Follow a workgroup's stored records as they arrive.
stream:latest
Client → server. Start following a table's records as they arrive.
Records come back on stream:latest:data — anything replayed from offset or timestamp first, then each new record as the cloud receives it — until you send stream:latest:stop or the connection closes. With neither offset nor timestamp, the subscription starts at the next record to arrive and nothing already stored is replayed.
The stream holds about an hour of records, so offset and timestamp reach back that far and no further. A subscriber that has been away for longer has a gap only a search can fill — see GET /tables/{orgName}/{table}/search on the HTTP API.
One connection can hold several subscriptions at once; the requestId you send and the streamId you get back tell their frames apart.
Streaming audit_logs needs Read audit logs and is refused without it. The - wildcard is accepted without that permission, but audit records are then left out of the stream.
Subscribing more than 20 times in 60 seconds is refused, as a frame carrying error. Every subscription is recorded in the workgroup's audit log.
requestId
string
yes
An id you generate, echoed on every frame this subscription produces. A request without one is refused.
table
string
The table to follow, or - for every table the token can read. Table names come from GET /tables/{orgName} on the HTTP API. Defaults to -.
offset
integer or string
Resume from a stream position, as carried by the offset of an earlier frame — that offset to receive the record again, one greater to carry on after it, or 0 for the oldest record still held, about an hour back. Send it back as the decimal string it arrived as — the value can exceed what a JavaScript number holds exactly.
timestamp
string or integer
Start from a point in time rather than an offset, given as epoch milliseconds or a date string. Cannot reach further back than the stream's one-hour window. Ignored when offset is supplied.
includeDeviceEvents
boolean
Also deliver the device's own state changes, which arrive as frames with a kind of agentState. Defaults to false.
stream:latest:data
Server → client. Receive the records a subscription produces.
Every frame is a single CBOR-encoded binary payload, so decode it before reading it. Frames from all of a connection's subscriptions arrive on this one event — match on requestId or streamId.
A token restricted to a device group receives only that group's devices; records from other devices are dropped rather than refused.
Payload is application/cbor.
requestId
string
The requestId of the subscription this frame belongs to.
streamId
string
The subscription's server-side id, assigned when it starts. Pass it to stream:latest:stop to close the subscription.
offset
string
This record's position in the stream, as a decimal string because the value exceeds a JavaScript number. Keep the last one you saw to resume after a disconnection.
result
object
The record. Absent on an error frame.
result.kind
string
device for a data record, agentState for a device state change. One of device, agentState.
result.metadata
object
Where the record came from and when.
result.metadata.device
string
Device ID.
result.metadata.table
string
result.metadata.source
string
result.metadata.event_time
string
When the reading was taken, per the device.
result.metadata.source_time
string
When the device read it from the source.
result.data
object
The record itself — device, source, event_time, store_time and msg_id, plus one entry per column of the table.
error
string
Why the subscription could not be started or continued. Present instead of result.
A record arriving on a subscription to the test3 table:
stream:latest:stop
Client → server. Stop a subscription.
Closes one subscription and releases its consumer on the cloud. There is no acknowledgement: no further frames carrying that streamId arrive, though frames already in flight may still be delivered. A streamId that is unknown, or already stopped, is ignored.
Each subscription holds a consumer open on the cloud, so stop the ones you no longer read. Closing the connection stops all of its subscriptions.
streamId
string
yes
The subscription to close, as carried by the streamId of its frames.
Search
Run a search and receive the matching records page by page, instead of waiting for one large HTTP response.
search
Client → server. Search a table and receive the records page by page.
The same search as GET /tables/{orgName}/{table}/search, delivered as it is read rather than as one response.
The answer arrives in three parts — a search:rpc frame with the match count, then a search:reply frame per page, then a final search:reply with complete: true.
Include scroll in the query and the cloud pages through the whole result set for you, one search:reply per page, with no scroll id to manage and no ceiling on the total — the reason to search over a socket rather than over HTTP. Without scroll you get a single page of rows records, 50 by default, and then the completion frame.
A failure arrives on search:rpc instead, carrying error and complete: true, and no pages follow. A search that fails partway through delivery ends without a completion frame, so treat the absence of complete as an incomplete result rather than assuming the last page you saw was the last one.
Searching audit_logs needs Read audit logs.
requestId
string
yes
An id you generate, carried back on every frame of the answer.
table
string
yes
The table to search.
timezone
string
IANA timezone name used to resolve the query's timeframe and date filters. An unrecognised name falls back to Etc/UTC. Defaults to Etc/UTC.
query
object
The search itself, in the same shape as the query parameters of GET /tables/{orgName}/{table}/search on the HTTP API — filters, fields, sort, rows, aggs, timeframe and dateField. Unlike the HTTP endpoint, each is a real value rather than a JSON-encoded string. Omit it to return everything in the table.
query.scroll
any
Include this key, with any value, to have the cloud page through the whole result set. Without it a single page of rows records is delivered. Cannot be combined with aggs.
query.rows
integer
Records per page. The ceiling is on the page, not on the total: with scroll, as many pages as the result set needs are delivered. Defaults to 50.
query.filters
array of object
Conditions to apply, combined with AND. Anything that is not an array is ignored.
query.timeframe
string
The period to search, for example 7 days ago or 2026-08-01 until 2026-08-08.
search:rpc
Server → client. Receive the search's match count, or the reason it failed.
requestId
string
totalRecords
integer
How many records matched, which may exceed the number delivered. Sent before the first page.
took
integer
Query execution time in milliseconds.
complete
boolean
Present, and true, only on a failure.
result
string
Present only on a failure. One of error.
statusCode
integer
The HTTP status the same failure would carry on the REST API — 400 for a malformed query.
error
string
Why the search failed. Search failed: reason unknown means the cause was internal and has been logged.
search:reply
Server → client. Receive each page of matching records.
requestId
string
records
array of object
The matching rows, one object per record. Absent on the final frame.
aggregations
object
Present only when the query asked for aggregations.
complete
boolean
Present, and true, on the final frame, which carries no records.
result
string
Present only on the final frame. One of success.
Live feeds
Readings straight off a device's telemetry queue, before they are stored. Lower latency than a stream, but nothing is replayed and nothing is kept — a feed only carries what arrives while it is open.
device:feed
Client → server. Open a live feed on one of a device's streams.
Delivers each reading as the device sends it, straight off the telemetry queue and before it is stored. Use it for a live gauge or chart; use stream:latest when you need records that are already stored, or the ability to resume where you left off.
The cloud answers on device:feed:rpc with a feedId, then sends each reading on device:feed:reply. Nothing is replayed: a feed carries only what arrives while it is open.
Needs Read. Closing the connection closes every feed it opened.
requestId
string
yes
An id you generate, carried back on the answer and every reading.
deviceId
string
yes
The device to read from.
table
string
source
string
column
string
For a CSV-type scenario, the one field to deliver. Omit to receive every field of each reading. A name the scenario does not have is rejected.
includeMeta
boolean
Return the scenario's field definitions on the answer, so the values can be labelled without a separate metadata call. Defaults to false.
device:feed:rpc
Server → client. Receive the feed's id, or the reason it could not be opened.
requestId
string
feedId
string
The feed's id. Pass it to device:feed:stop to close the feed.
meta
object
The scenario's definition, including its fields in the order their values arrive. Present only when includeMeta was set.
error
object
Present instead of feedId when the feed could not be opened.
error.code
string
feed001 when deviceId is missing. A permission refusal carries its own code.
error.message
string
device:feed:reply
Server → client. Receive each reading from a live feed.
requestId
string
The requestId of the feed this reading belongs to.
feedId
string
device
string
Device ID.
table
string
source
string
field
string
The column asked for, or null when the whole reading is delivered.
event_time
string
When the device took the reading.
messageId
string
The agent's id for this message.
value
any
The reading — a single value when column was given, otherwise the scenario's values in field order.
device:feed:stop
Client → server. Close one live feed.
Closes a single feed, whether it was opened by device:feed or device:bulkFeed. There is no acknowledgement.
feedId
string
yes
The feed to close, as returned on device:feed:rpc or device:bulkFeed:rpc.
device:feed:stopAll
Client → server. Close every live feed on this connection.
Closes all of the connection's feeds at once, without needing their ids. There is no acknowledgement.
No payload.
device:bulkFeed
Client → server. Open one live feed covering many device streams.
The same delivery as device:feed, for many streams at once and with the values already labelled by field name. This is what a dashboard of many tiles should use — one feed rather than one per tile.
Readings arrive on device:bulkFeed:reply, each naming the device, table and source it came from. A reading whose stream was not asked for is not delivered.
Needs Read. A token restricted to a device group has streams for other devices dropped from the request, without an error, so check what arrives rather than assuming every stream is live.
requestId
string
yes
An id you generate, carried back on the answer and every reading.
streams
array of object
yes
The streams to follow. Anything that is not an array is rejected with feed002.
streams[].deviceId
string
yes
streams[].table
string
yes
streams[].source
string
yes
streams[].field
string
yes
The one field of that stream to deliver.
streams[].type
string
The field's data type, as reported in the device's metadata.
device:bulkFeed:rpc
Server → client. Receive the bulk feed's id, or the reason it could not be opened.
requestId
string
feedId
string
The feed's id, covering every stream in the request. Pass it to device:feed:stop to close the whole feed.
error
object
Present instead of feedId when the feed could not be opened.
error.code
string
feed002 when streams is not an array.
error.message
string
device:bulkFeed:reply
Server → client. Receive each reading from a bulk live feed.
requestId
string
feedId
string
device
string
Device ID. Together with table and source, this says which stream the reading is for.
table
string
source
string
event_time
string
messageId
string
data
object
The reading, keyed by field name, narrowed to the fields asked for on that stream.
Notifications
Events the cloud pushes without being asked. A connection receives these for every workgroup its token covers, not only the one named at handshake, so check the workgroup on each one before acting.
device:stateChange
Server → client. A device came online or went offline.
Sent as the cloud sees the device's connection open or close, which is not the same as the device being healthy — a device can hold a connection and still have stopped reporting. GET /devices/{orgName}/device/status is what answers that.
id
string
Device ID. Older agents identify themselves by cn instead, so read whichever is present.
cn
string
The device's certificate subject, whose O= part names the workgroup.
online
boolean
Whether the device now holds a connection to the cloud.
vhost
string
The workgroup the device belongs to.
device:new
Server → client. A device was added to a workgroup.
id
string
Device ID.
name
string
cn
string
The device's certificate subject, whose O= part names the workgroup this device was created in.
device:metaChange
Server → client. A device reported new metadata.
A device re-reports its metadata whenever its configuration changes, including when a new one is applied through this API. Several can arrive in quick succession for one change.
id
string
The device whose metadata changed. The metadata itself is not included — read it from GET /devices/{orgName}/{device}.
incident
Server → client. An alert raised an incident, or an incident was resolved.
Sent when an alert's condition is first met, and again when it clears — the second carries resolved: true, and both carry the same _id. An incident that keeps firing is not re-sent.
Acknowledging an incident does not produce one of these.
_id
string
The incident's id.
workgroupId
string
The workgroup the incident belongs to, which is not necessarily the one this connection is bound to.
alert
string
The id of the alert whose condition was met.
scenario
string
The table and source the alert was watching.
severity
string
categories
array of string
The alert's categories, as configured on it.
active
boolean
Whether the alert's condition is still met.
resolved
boolean
Present, and true, only on the notice that an incident has cleared.
event
object
The reading that met the condition.
lastAlert
string
acknowledged
array of string
The users who have acknowledged the incident.
createdAt
string
updatedAt
string
job
Server → client. A background job changed.
Sent as a job progresses, so a long-running task can be followed without polling. Counts and status are updated in place; the same _id arrives repeatedly.
_id
string
workgroupId
string
The workgroup the job belongs to, which is not necessarily the one this connection is bound to.
task
string
The task this job is one run of.
type
string
status
string
Where the job is up to.
outcome
string
How it finished.
entity
object
What the job is acting on.
entity.type
string
entity.id
string
entity.name
string
count_run
integer
count_success
integer
count_fail
integer
start
string
end
string
last_run
string
comments
string
results
object
Whatever the job produced, shaped by its type.
deviceSchedule
Server → client. A device schedule was created or changed state.
Sent each time a schedule moves — drafted, sent to the device, applied, replaced or failed. Follow state to know whether a schedule is actually running on the device.
_id
string
workgroupId
string
The workgroup the schedule belongs to, which is not necessarily the one this connection is bound to.
deviceId
string
The device the schedule applies to.
setpoint
string
The setpoint the schedule drives.
schedule
string
The parent schedule this one was derived from, where there is one.
name
string
description
string
state
string
Where the schedule is in its life. Pending is on its way to the device, Applied is running there, Replaced was superseded by a later one. One of Draft, Pending, Applied, Error, Replaced.
entries
array of object
The schedule's points, each a timestamp and a value.
createdAt
string
updatedAt
string
deviceSetpoint
Server → client. A device setpoint was created or changed.
_id
string
workgroupId
string
The workgroup the setpoint belongs to, which is not necessarily the one this connection is bound to.
deviceId
string
name
string
path
string
Where on the device the value is written.
source
string
scheduleFormat
string
defaultUnit
string
maxPower
number
currentDeviceSchedule
string
The schedule now driving this setpoint.
pendingDeviceSchedule
string
The schedule on its way to the device, where there is one.
createdAt
string
updatedAt
string
Last updated
Was this helpful?