xPlantAPI
API referenceDevices

Register a device

Adds a sensor, controller or gateway to the workspace so it can send heartbeats, readings and events. Then mint a device token for it and put that token on the device, rather than a workspace key.

POST/api/v1/devices
Scope write:devicesHonours Idempotency-Key

If the workspace has already connected every device its plan includes, or its plan includes none, the request is refused with DEVICE_LIMIT_REACHED. A retired device does not count. Send an Idempotency-Key so a retried request cannot register the same device twice.

Send an Idempotency-Key header to make retries safe: a repeat with the same key within 24 hours returns the first response instead of writing twice. See Idempotency.

Headers

NameTypeRequiredDescription
Idempotency-KeystringNoAny unique string you choose per logical write. A retry carrying the same key within 24 hours returns the first result instead of writing again. Scoped to your API key and this operation. 8–255 characters. Must match ^[A-Za-z0-9._:~-]+$.

Request body

FieldTypeRequiredDescription
namestringYesWhat the lab calls the device, as it appears in the device list. 1–100 characters.
type"sensor" | "controller" | "gateway"NoWhat kind of device this is. Default "sensor".
hardwarestringNoThe board or model, for example Raspberry Pi 4. Up to 100 characters.
firmware_versionstringNoThe firmware or software version the device runs. Up to 50 characters.
room_idstring (uuid)NoThe growing room the device sits in. Must be a room in the workspace.
metadataobjectNoAny JSON object you want kept with the device. Default {}.

Example

curl -X POST https://app.xplantpro.com/api/v1/devices \
  -H "Authorization: Bearer $XPLANT_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{
    "name": "Shelf 3 climate probe",
    "type": "sensor",
    "hardware": "Raspberry Pi 4",
    "firmware_version": "1.4.2",
    "room_id": "2c6f9a41-7d3e-4b8a-a1c5-9e0d4f7b3a26",
    "metadata": {
      "shelf": 3
    }
  }'

Response

201 with { "ok": true, "data": … }. data holds the result.

FieldTypeRequiredDescription
idstring (uuid)Yes—
namestringYes—
typestringYesOne of sensor, controller, gateway.
hardwarestring | nullYes—
statusstringYesactive while the device is in service. paused or retired once someone in the lab takes it out of service, which refuses its readings and revokes its device tokens.
firmware_versionstring | nullYes—
room_idstring | null (uuid)YesThe growing room the device sits in, if one was set.
last_seen_atstring | nullYesWhen the device was last heard from, as an ISO 8601 timestamp. A heartbeat updates it. Null if it has never been heard from.
metadataobjectYesThe JSON object stored with the device when it was registered.
created_atstringYes—
updated_atstringYes—
Response
{
  "ok": true,
  "data": {
    "id": "8e3b1f52-6c0d-4a7e-9b21-5f4d8c2a7e13",
    "name": "Shelf 3 climate probe",
    "type": "sensor",
    "hardware": "Raspberry Pi 4",
    "status": "active",
    "firmware_version": "1.4.2",
    "room_id": "2c6f9a41-7d3e-4b8a-a1c5-9e0d4f7b3a26",
    "last_seen_at": null,
    "metadata": {
      "shelf": 3
    },
    "created_at": "2026-09-01T09:30:00.000Z",
    "updated_at": "2026-09-01T09:30:00.000Z"
  }
}
Response headerMeaning
Idempotent-Replaytrue when this response is a replay of an earlier request with the same Idempotency-Key.
X-Request-IdIdentifies this request. Include it when you contact support.

Errors

StatusCodeWhen
400VALIDATION_ERRORThe request body is not valid JSON.
401UNAUTHORIZEDThe key is missing, malformed or revoked, or its owner is no longer a member of the workspace.
402PAID_PLAN_REQUIREDThe workspace has no paid plan. Connecting devices is included with every paid plan.
402DEVICE_LIMIT_REACHEDThe workspace has connected every device its plan includes — retire a device it no longer uses, or contact support to raise the limit — or its plan includes no connected devices at all. error says which. Nothing was registered.
403FORBIDDENThe key lacks a scope this operation requires, or its owner's current role in the workspace cannot use it — a key never does more than its owner can in xPlant. error names the scope, and for a role, the role it needs.
403DEVICE_TOKEN_NOT_ACCEPTEDA device token was sent; this operation needs a workspace API key.
404NOT_FOUNDroom_id does not name a growing room in the workspace. Nothing was registered.
409IDEMPOTENCY_IN_FLIGHTA request with this Idempotency-Key is still being processed; retry after Retry-After seconds.
422VALIDATION_ERRORThe Idempotency-Key header is malformed.
422VALIDATION_ERRORA field failed validation. error names the first one, for example name: String must contain at least 1 character(s).
429RATE_LIMIT_EXCEEDEDToo many requests for this key, device token or workspace. Wait Retry-After seconds.
500DEVICE_CREATE_FAILEDThe device could not be saved. Retry with the same Idempotency-Key.
503DEVICE_LIMIT_UNAVAILABLEThe workspace's device allowance could not be checked, so nothing was registered. Retry shortly.

Branch on code, never on the error text. See Errors.

On this page