Referencia GraphQL: device-state
Generada a partir del esquema que sirve este servicio, así que no puede quedarse atrás. El mismo esquema se publica como archivo para herramientas y agentes.
| Endpoint | https://<your-host>/api/device-state/graphql |
| Plano de autenticación | tenant — The ordinary application plane. Obtain a tenant access token by calling login then selectTenant on user-management, and authorize each call with the capability it names (for example device:write). |
| Autorización | tenant access token |
| Archivo del esquema | /schema/device-state.graphql |
| Descritos | 105 de 105 elementos |
La referencia que sigue se genera a partir del esquema y está solo en inglés.
Queries
assertedDeviceStates · deviceStates · deviceStatesByDeviceToken · deviceStatesByExternalId · droppedMeasurements · latestLocation · latestLocations · latestMeasurements
assertedDeviceStates
Returns one page of the ASSERTED device states that belong to one event source, in ascending id order: the set an adapter reconciles against after a failover. Walk it with a cursor: pass the id of the last row of the previous page as afterId and keep asking until a page comes back with fewer rows than pageSize. A pageSize outside 1 to 1000 is an error, not adjusted. Requires state:read, and is refused to a member whose access is limited to some customers.
Returns [DeviceState!]!
| Argument | Type | Description |
|---|---|---|
activeOnly | Boolean! | Required. True returns only the devices the projection believes are online; false also returns the ones it believes are offline. |
afterId | ID | Cursor: the id of the last row of the previous page. Omit for the first page. A non-numeric value is an error. |
pageSize | Int! | Rows per page, between 1 and 1000 inclusive; anything else is an error. |
source | String! | The event source, exactly as DeviceState.source reports it. |
deviceStates
Searches device states, newest first, one page at a time. Requires state:read. A member whose access is limited to some customers sees, and has counted, only the devices those customers own now.
Returns DeviceStateSearchResults!
| Argument | Type | Description |
|---|---|---|
criteria | DeviceStateSearchCriteria! | Filter and page to return. |
deviceStatesByDeviceToken
Returns the states of the given devices, in no particular order. Devices with no state yet are omitted. Requires state:read. A member whose access is limited to some customers sees only the devices those customers own now; any other device is omitted.
Returns [DeviceState!]!
| Argument | Type | Description |
|---|---|---|
deviceTokens | [String!]! | Tokens of the devices. More than 1000 is refused with LIMIT_EXCEEDED. |
deviceStatesByExternalId
Returns the states of the devices carrying the given external ids, in no particular order. External ids that match nothing are omitted. Requires state:read. A member whose access is limited to some customers sees only the devices those customers own now.
Returns [DeviceState!]!
| Argument | Type | Description |
|---|---|---|
externalIds | [String!]! | External ids of the devices, as reported in DeviceState.externalId. More than 1000 is refused with LIMIT_EXCEEDED. |
droppedMeasurements
Returns the measurement keys this device sent that the platform discarded, ordered by key then reason, each with the reason, the last value, how often and when. Empty when nothing is being discarded. Declare a key as a numeric metric on the device's profile to store it. Requires state:read. Empty for a member whose access is limited to some customers when none of them owns the device now.
Returns [DroppedMeasurement!]!
| Argument | Type | Description |
|---|---|---|
deviceToken | String! | Token of the device. |
latestLocation
Returns the last-known position of one device, or null when it has never been located. Requires location:read. Null for a member whose access is limited to some customers when none of them owns the device now.
Returns LatestLocation
| Argument | Type | Description |
|---|---|---|
deviceToken | String! | Token of the device. |
latestLocations
Returns the last-known position of each of the given devices, ordered by device token. A device that has never been located is absent from the result. Requires location:read. A member whose access is limited to some customers sees only the devices those customers own now.
Returns [LatestLocation!]!
| Argument | Type | Description |
|---|---|---|
deviceTokens | [String!]! | Tokens of the devices. More than 1000 is refused with LIMIT_EXCEEDED. |
latestMeasurements
Returns the current value of every measurement the device has reported, ordered by measurement name. Empty when the device has reported none. Requires state:read. Empty for a member whose access is limited to some customers when none of them owns the device now.
Returns [LatestMeasurement!]!
| Argument | Type | Description |
|---|---|---|
deviceToken | String! | Token of the device. |
Mutations
demoteAssertedPresence
Returns one page of an event source's ASSERTED device states to INFERRED presence, releasing that source's custody of them so the ordinary activity and inactivity rules apply again. It asserts nothing about connectivity: active and the connect, disconnect and alarm timestamps are unchanged. Walk the source by passing the previous result's lastId as afterId. Requires state:demote, which is separate from state:read.
Returns PresenceDemotionResult!
| Argument | Type | Description |
|---|---|---|
afterId | ID | Cursor: the lastId of the previous page. Omit for the first page. A non-numeric value is an error. |
deviceTokens | [String!] | Optional narrowing within the source. Omit or null to demote the whole source; a non-empty list restricts to those devices (a token belonging to another source is not found, never demoted); an empty list demotes nothing; more than 1000 is refused with LIMIT_EXCEEDED. |
limit | Int! | Rows to examine on this page, between 1 and 1000 inclusive; anything else is an error, not clamped. |
reason | String! | Why the source is being demoted. Required and must not be blank; it is stamped onto every emitted event with your identity and logged, and is the only record of the change. |
source | String! | The event source whose devices to demote, exactly as DeviceState.source reports it. Required and never inferred. A source nobody uses matches no rows. |
Objects
DeviceState · DeviceStateSearchResults · DroppedMeasurement · LatestLocation · LatestMeasurement · PresenceDemotionResult · SearchResultsPagination
DeviceState
object
The live connectivity and activity state of one device, projected from its events. One row per device, created when the device first produces an event or presence signal.
Implements Model
| Field | Type | Description |
|---|---|---|
active | Boolean! | Whether the device is currently considered connected. For an INFERRED device it becomes true on activity and false when no activity arrives within inactivityTimeout. For an ASSERTED device it follows only the connect and disconnect signals of its event source. |
createdAt | String | When the row was first created, as an RFC 3339 timestamp. |
deletedAt | String | When the row was deleted, as an RFC 3339 timestamp. Deleted rows are not returned by this API, so this is null in practice. |
deviceToken | String! | Token of the device this state belongs to. |
droppedMeasurementCount | Int! | How many distinct measurement keys from this device are being discarded: the number of (key, reason) rows droppedMeasurements returns for it, not a count of events. Zero when nothing is. A badge, cheap enough to ask for on a page of devices. Counts what the caller can see, so it is zero for a member whose access is limited to some customers when none of them owns the device now. |
externalId | String | The device's transport-native identity, copied from the events it sends; null when the device has no external id. |
id | ID! | Server-assigned numeric identifier of the row, serialized as a string. Rows are addressed by device token; this id is also the cursor for assertedDeviceStates and demoteAssertedPresence. |
inactivityAlarmTime | String | When the inactivity sweep marked the device inactive for going silent, as an RFC 3339 timestamp. Cleared when the device becomes active again; null otherwise, including for a device that went offline by a disconnect report rather than by silence. Deprecated: it keeps working as before until the next major release. Deprecated. Use lastDisconnectTime, which holds the same instant when the sweep marked the device inactive, unless a disconnect report followed, and also covers a disconnect report. This field keeps its behaviour until the next major release. |
inactivityTimeout | Int! | Seconds without activity after which an INFERRED device is marked inactive. One value for the whole platform (600); it is not configurable per device. It does not apply to an ASSERTED device. |
lastActivityTime | String | Time of the most recent event from the device, as an RFC 3339 timestamp; null if none. Taken from the event's own occurrence time, so an older event delivered late does not move it backwards. |
lastConnectTime | String | When the device was last considered to have connected, as an RFC 3339 timestamp; null if it has not. |
lastDisconnectTime | String | When the device was last considered to have disconnected, as an RFC 3339 timestamp. For an INFERRED device this is the moment the inactivity check marked it inactive, not the time of its last event. Null if it has not disconnected. |
presenceSource | String! | How presence is decided: INFERRED (from activity and the inactivity timeout) or ASSERTED (the event source states connect and disconnect explicitly, and activity alone cannot change it). |
presenceTime | String | Time of the last applied presence transition, as an RFC 3339 timestamp; null until one has been applied. |
sessionId | String! | Ordering epoch of the last applied presence transition, serialized as a string because it is a nanosecond-scale integer too large for a GraphQL Int. "0" until the first presence signal. |
source | String | The event source that last drove this device; null before the device has produced an event carrying one. MQTT and HTTP report the event source's own configured id (for example mqtt1), LwM2M reports lwm2m, and Sparkplug reports sparkplug:{hostId}. To classify a device by transport, cut at the first ':' and compare that part, because the first two forms are operator-chosen. Pass this value exactly as reported when you need a source argument elsewhere. |
updatedAt | String | When the row was last modified, as an RFC 3339 timestamp. |
DeviceStateSearchResults
object
One page of device states.
| Field | Type | Description |
|---|---|---|
pagination | SearchResultsPagination! | Where this page sits within all matching device states. |
results | [DeviceState!]! | The device states on this page. |
DroppedMeasurement
object
A measurement key a device sent that the platform discarded while it stored the rest of the message, and why. One row per device, key and reason, so a device that sends the same text key in every message is one row with a growing count. At most 32 rows are kept per device; past that the row last seen longest ago is dropped. Declare the key as a numeric metric on the device's profile to store it.
Implements Model
| Field | Type | Description |
|---|---|---|
count | Int! | How many times the key was discarded. A message the platform delivers twice can count twice, so read it as how often, not as an exact total. Stops growing at 2147483647. |
createdAt | String | When the row was first created, as an RFC 3339 timestamp. |
deletedAt | String | When the row was deleted, as an RFC 3339 timestamp. Deleted rows are not returned by this API, so this is null in practice. |
deviceToken | String! | Token of the device that sent the key. |
firstTime | String! | When the key was first discarded, as an RFC 3339 timestamp: the earliest the device sent it. |
id | ID! | Server-assigned numeric identifier of the row, serialized as a string. Rows are addressed by device token. |
lastTime | String! | When the key was last discarded, as an RFC 3339 timestamp: the latest time the device sent it. A message delivered late does not move it back. |
lastValue | String! | The value the device last sent under this key, cut to 64 bytes. It is the device's own content and is visible to the same readers as the device's latest measurement values. |
name | String! | The measurement key that was discarded, for example status_text. |
reason | DroppedMeasurementReason! | Why it was discarded. |
updatedAt | String | When the row was last modified, as an RFC 3339 timestamp. |
LatestLocation
object
The last-known position of a device: the "where is it right now?" view that sits beside the append-only location history. One row per device. Coordinates are WGS84 decimal degrees; elevation and accuracy are in metres, speed in metres per second, heading in degrees clockwise from true north. Reading it requires location:read, which is separate from state:read.
Implements Model
| Field | Type | Description |
|---|---|---|
accuracy | Float | Accuracy of the fix in metres; null when not reported. |
createdAt | String | When the row was first created, as an RFC 3339 timestamp. |
deletedAt | String | When the row was deleted, as an RFC 3339 timestamp. Deleted rows are not returned by this API, so this is null in practice. |
deviceToken | String! | Token of the device the position belongs to. |
elevation | Float | Elevation in metres above the ellipsoid (not mean sea level); null when not reported. |
heading | Float | Heading in degrees clockwise from true north, in the range 0 to 360 (360 excluded); null when not reported. |
id | ID! | Server-assigned numeric identifier of the row, serialized as a string. Rows are addressed by device token. |
latitude | Float | Latitude in decimal degrees (WGS84, EPSG:4326); null when the fix did not report it. Null is not the same as 0. |
longitude | Float | Longitude in decimal degrees (WGS84, EPSG:4326); null when the fix did not report it. Null is not the same as 0. |
occurredTime | String! | When the fix was taken, as an RFC 3339 timestamp. An older fix delivered late does not replace a newer stored one. |
speed | Float | Speed in metres per second; null when not reported. |
updatedAt | String | When the row was last modified, as an RFC 3339 timestamp. |
LatestMeasurement
object
The most recent value of one named measurement for a device: the live "what is it now?" view that sits beside the append-only measurement history. One row per device and measurement name.
Implements Model
| Field | Type | Description |
|---|---|---|
classifier | Int | Id of the metric definition the reading was bound to; null for a measurement with no definition. |
createdAt | String | When the row was first created, as an RFC 3339 timestamp. |
dataType | String | Data type copied from the bound metric definition (it lets a consumer render a 0/1 BOOLEAN value as false/true); null for an undeclared measurement. |
deletedAt | String | When the row was deleted, as an RFC 3339 timestamp. Deleted rows are not returned by this API, so this is null in practice. |
deviceToken | String! | Token of the device the reading belongs to. |
id | ID! | Server-assigned numeric identifier of the row, serialized as a string. Rows are addressed by device token. |
name | String! | Name of the measurement, for example a metric name such as temperature. |
occurredTime | String! | When the reading was taken, as an RFC 3339 timestamp. An older reading delivered late does not replace a newer stored one. |
unit | String | Unit of measure copied from the bound metric definition; null for an undeclared measurement. |
updatedAt | String | When the row was last modified, as an RFC 3339 timestamp. |
value | Float | The numeric value of the most recent reading. Only numeric readings are stored, so in practice this is always set. |
PresenceDemotionResult
object
The outcome of one page of a presence demotion.
| Field | Type | Description |
|---|---|---|
demoted | Int! | How many demotion events were published, handing those devices back to inferred presence. The events are applied asynchronously. |
lastId | ID | Id of the last row scanned: pass it as afterId on the next call. Null when the page was empty. |
scanned | Int! | How many ASSERTED rows this page examined. Keep walking while it equals the limit you asked for; stop on the first page that comes back short. Do not use demoted as the stop signal. |
skipped | Int! | Rows this page examined but could not release, which is scanned minus demoted. A row is skipped when it holds no presence time, or when its presence time is not in the past. A page that skips everything is a signal, not a failure. |
SearchResultsPagination
object
Where one page of search results sits within the full result set. Positions are 1-based and inclusive.
| Field | Type | Description |
|---|---|---|
pageEnd | Int | Position of the last result of this page within the full result set (1-based, inclusive). Capped at totalRecords. |
pageStart | Int | Position of the first result of this page within the full result set (1-based). |
totalRecords | Int | Number of records matching the criteria across all pages. |
Interfaces
Model
interface
Fields common to every stored row.
| Field | Type | Description |
|---|---|---|
createdAt | String | When the row was first created, as an RFC 3339 timestamp. |
deletedAt | String | When the row was deleted, as an RFC 3339 timestamp. Deleted rows are not returned by this API, so this is null in practice. |
id | ID! | Server-assigned numeric identifier of the row, serialized as a string. Rows are addressed by device token. |
updatedAt | String | When the row was last modified, as an RFC 3339 timestamp. |
Input types
DeviceStateSearchCriteria
input
Filter and paging for searching device states. Results are newest first (by row creation). To look up specific devices use deviceStatesByDeviceToken.
| Input field | Type | Description |
|---|---|---|
active | Boolean | Only devices whose active flag equals this value. Omit to include both. |
pageNumber | Int! | Page to return, starting at 1; values below 1 are treated as 1. |
pageSize | Int! | Results per page. Values below 1 become 100; values above 1000 are capped at 1000. |
Enums
DroppedMeasurementReason
enum
Why a measurement key sent by a device is discarded while the rest of its message is stored. In every case the remedy is the same: declare the key as a numeric metric on the device's profile to store it.
| Value | Description |
|---|---|
UNDECLARED_NON_NUMERIC | The key is not declared on the profile and its value is not a number, for example the text "ok". |
UNDECLARED_UNSTORABLE | The key is not declared on the profile and its value is a number that cannot be stored: not a number (NaN), infinite, or beyond the range of a stored measurement. |
DECLARED_NOT_STORABLE | The key is declared on the profile with a data type that is not a time-series metric. |