State stores keyed values such as temperature, connectivity, or settings. APIs select the destination with a Unit ID: machine-<Machine ID> for a Machine or account-<Account ID> for an Account. See the glossary to distinguish Machine IDs from obniz IDs.
Reads require Read permission for units; changes require Write permission. User sessions also apply role and group restrictions. See API authentication.
Retrieve current values and revisions
GET /api/1/units/account-<Account ID>/states
Authorization: Bearer <Account API Token>
The response is an object keyed by State name, not an array.
{
"alert_threshold": {
"value": 30,
"ts": "2026-10-13T00:00:00Z",
"revision": "7"
}
}
revision is a string identifying a version. Keep it unchanged rather than converting it to a number. Use subscriptions for ongoing changes.
Update only if the version still matches
When several screens or jobs write the same setting, send the revision you read with PUT. This prevents overwriting an intervening change.
PUT /api/1/units/account-<Account ID>/states/alert_threshold
Authorization: Bearer <Account API Token>
Content-Type: application/json
{"value":32,"expectedRevision":"7"}
Success returns the updated value, ts, and revision. To allow initial creation only, send expectedRevision: null; an existing value causes a conflict.
| Result | Action |
|---|---|
409 state_revision_conflict |
Retrieve the latest value, reconcile changes, and submit a new update |
404 state_not_found |
Check whether the target was deleted |
409 template_managed |
Ask the administrator to change the managed value |
Automatically resending the same content after a conflict defeats the version check. Show the latest value and let the user reconcile it.
Value format
State values are strings or finite numbers. Booleans, objects, and null are not accepted directly. Use Unit Assets for JSON settings or files. Keys contain 1–255 characters; string values have a maximum of 65,535 Unicode code points.