Device Enrollment (register_device)

Device Enrollment (register_device)

https://easycms.fi/public_api/register_device/ — binds one Inventory Manager API credential (one API token row, or the legacy inventory pair) to one app installation. After enrollment, that credential only works from the enrolled device: every other API call must then carry the X-Device-ID and X-Device-Token headers. Credentials that are never enrolled keep working exactly as before — device binding is opt-in per credential, and only this endpoint can claim a credential (ordinary API endpoints never auto-enroll).

When the app calls this

Once, during account setup — after the user entered the account API credentials and before the first normal API call. Store the returned device_token in OS secure storage next to the credential; also generate and persist a random installation UUID (device_id) the first time the app runs and keep sending the SAME value forever.

Request

POST only, Content-Type: application/json, HTTPS only.

Authentication — exactly the fields the app already sends for every API call (see API Credentials):

  • Token mode (recommended): username, token, account (no header, no password)
  • Legacy mode: Authorization1 header + username, password, account

Enrollment fields:

Parameter Type Description
device_id string, required The installation UUID (or device MAC): 12–64 hex characters, with or without :/- separators. Generated once per installation, persisted securely, never changed
device_name string, optional Human-readable label, max 100 chars (shown to the account administrator)
platform string, optional One of android, ios, macos, windows, linux, web, unknown
app_version string, optional App version label, max 40 chars

Header (optional): Idempotency-Key: <random UUID> — persist it for this enrollment attempt. If the response is lost, a retry with the same key and the same body re-serves the original response including the one-time device token for 24 hours. A reused key with a changed body is rejected (409 idempotency_key_conflict).

Responses

First enrollment — 201 Created:

{
  "ok": true,
  "status": "registered",
  "device": {
    "device_id": "6aa5a978-89bd-49f7-9a8d-21e446c58e71",
    "device_name": "Front counter iPad",
    "platform": "ios",
    "app_version": "1.0.7+10",
    "bound_at": "2026-11-11T09:30:00Z"
  },
  "device_token": "<64-char opaque token — shown ONCE, store it securely>"
}

device.device_id echoes the device_id you sent verbatim (separators and case preserved) — compare it directly against your persisted installation id. Internally the CMS stores a canonical form (lowercased, separators stripped), so any separator/case variant of the same id resolves to the same binding.

Retry from the same device with the valid device token (X-Device-Token header) — 200 OK: status: "already_registered", the binding is NOT rotated and the raw token is never returned again.

Error codes:

HTTP Code Meaning
400 invalid_device_request Not POST, not HTTPS, invalid device_id, invalid platform, or conflicting auth fields (token mode + Authorization1 header)
403 device_token_invalid Same device_id but the device token is missing/wrong — re-enrollment is not a recovery mechanism; ask an administrator to release the binding
409 credential_bound_to_another_device A different installation already holds this credential. Ask an administrator to release it first (Settings → APIs → Inventory Manager app → Clear device binding)
409 idempotency_key_conflict The Idempotency-Key was reused with a different request body
429 rate_limited Too many enrollment attempts (20 / 5 min / account)
404 family UN-AUTHORIZED ... The account credential itself failed — the API's standard auth error family

The 409 response never reveals which device holds the binding.

After enrollment — every normal API call

Attach BOTH headers to every request to any other public_api endpoint (reads, writes, verify_user, picking — all of them):

X-Device-ID: 6aa5a97889bd49f79a8d21e446c58e71
X-Device-Token: <the opaque device token from registration>

Rules the server enforces:

  • Missing headers, a wrong device ID or a wrong device token all answer HTTP 404 with UN-AUTHORIZED - this token is used by another device, please request a new token! — one message, never disclosing the bound device.
  • The binding cannot be changed or released from the app — a device change (new phone, reinstall with a new UUID) requires the platform super admin to clear the binding in the CMS first; the app should surface the error message and direct the user to support.
  • Deleting the API token row in the CMS (or regenerating its value) deletes the binding with it — the new token value starts unbound.
  • The device token is a secret equal to the API credential itself: never log it, never send it in a URL, only over HTTPS.

Security notes

  • device_id is an identifier, not proof of hardware identity — a copied UUID plus the device token can still impersonate the installation. This binding prevents ordinary reuse of a leaked API token on another device.
  • The server stores only a SHA-256 hash of the device token; the raw value exists only in the enrollment response (and in the 24-hour idempotency replay record).
  • Failed device checks are rate-limited and feed the platform's API ban ladder, like every other authentication failure.