Register a device
const url = 'http://127.0.0.1:9090/api/tenants/acme/devices';const options = { method: 'POST', headers: { 'X-Request-Id': '4f1c2b0e-8a7d-4c51-9e2f-3a6b8d0c1e7f', 'Idempotency-Key': '0b6f1d3e-2c4a-4f8e-9a1b-7d5c3e2f1a09', Authorization: 'Basic <credentials>', 'Content-Type': 'application/json' }, body: '{"device":"CG0002","endpoint":"office","status":"allowed"}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url http://127.0.0.1:9090/api/tenants/acme/devices \ --header 'Authorization: Basic <credentials>' \ --header 'Content-Type: application/json' \ --header 'Idempotency-Key: 0b6f1d3e-2c4a-4f8e-9a1b-7d5c3e2f1a09' \ --header 'X-Request-Id: 4f1c2b0e-8a7d-4c51-9e2f-3a6b8d0c1e7f' \ --data '{ "device": "CG0002", "endpoint": "office", "status": "allowed" }'Adds a device to the register before it calls in, so it is let in (or
refused) on its first message as its status says, whatever its
endpoint’s new_devices says.
With key, the key is kept as the device’s new key and the package is
asked for the commands that give it to the device: they are queued and
returned in commands. The key is enforced once the device presents it.
The change is added to the audit trail.
Authorizations
Section titled “Authorizations”Parameters
Section titled “Parameters”Path Parameters
Section titled “Path Parameters”The tenant’s id.
Example
acmeHeader Parameters
Section titled “Header Parameters”An id to follow the request by: answered back in X-Request-Id, and in the log, the audit trail and the events the request causes. 1 to 128 letters, digits, -, _, . or :; anything else is replaced by a new id.
Example
4f1c2b0e-8a7d-4c51-9e2f-3a6b8d0c1e7fDoes the request once, however often it is sent with this key, for 24 hours: sent again with the same request, it is answered as it was the first time (Idempotent-Replayed: true); with another, 422; while the first runs still, 409.
Example
0b6f1d3e-2c4a-4f8e-9a1b-7d5c3e2f1a09Request Bodyrequired
Section titled “Request Bodyrequired”A device to register.
object
The device’s id, as its package identifies it: 1 to 64 printable
ASCII characters, none of them /, + or #. sn is taken too.
The endpoint it belongs to.
What other systems know the device by: system name to id.
object
The key it is to present: 1 to 128 characters, none of them control characters. The package is asked for the commands that give the device the key. Absent: it has no key and is taken at its word.
Free-form data from other systems, kept as given.
object
Example
{ "device": "CG0002", "endpoint": "office", "status": "allowed"}Responses
Section titled “Responses”Registered: the device, with its own labels, and the commands queued to give it its key (none without key).
A device and the commands queued for it by the change.
object
The commands queued to give the device its new key; empty when the key did not change.
A command: one message the package builds for a device, queued, handed
out and answered. Parameters the package marks sensitive are shown as
<redacted N bytes>, and so is the payload that carries them.
object
The package command it is (its key among the package’s commands).
The action it is a step of, if it is one.
When it finished (answered, cancelled or skipped); null until then.
When it was queued.
Not handed out by then, it never is.
A gate of its action: handed out on its own, and the steps after it wait for it to succeed.
The command’s id, unique across the gateway.
The lane it queues in.
Its parameters, by name, sensitive values redacted.
object
What the device is handed, as text (“” when it is not text).
What the device is handed, base64-encoded, when it is not text.
What the device answered, as text; null until it answers.
The result, base64-encoded, when the device returned something that is not text.
The code the device answered with, as the package reads it; null until it answers.
Parked until then: the device answered “not yet, ask again”.
When it was handed to the device; null until then.
Where a command stands: queued (waiting to be handed to the device),
offered (written into a reply to the device, no result yet), succeeded, failed,
unanswered (offered, then lost: the device answered a command handed out after it, and
it had been handed out twice; a result that comes later still completes it),
cancelled (taken back before it was handed out: its action was
cancelled or expired), skipped (an earlier step of its action failed
before it was handed out) or parked (waiting behind a gate of its
action that has not passed, or asked to be sent again later:
retry_at).
How many times it has been handed to the device (more than once when the device answered “not yet, ask again”).
The device as it is now.
object
The id the package identifies the device by: a serial number, a MAC address, a cloud id.
The endpoint it belongs to.
None for a device that was registered and has not called in yet.
How its messages have gone, counted by every instance that serves it.
object
Of those, the ones that failed: the package failed, no route matched, or what it changed could not be stored.
Messages that got past its key: taken in, or refused for its status.
Present while the device is held (a gate of one of its actions did not pass): nothing is handed to it until it is released, and what it sends is taken in as usual.
object
The action whose gate failed.
When the hold was taken.
Why: the gate that did not pass and what became of it.
The gate’s step in that action, counted from 1.
The device’s number in the register.
Facts the package reported: firmware, IP, user counts, capabilities.
object
Where it stands with its key.
When the device, while held, last presented a key other than the
one it was held with: someone else may be calling under its name.
Adopting takes the key it was held with all the same;
adopt_presented_key takes the latest instead. Cleared when its key
is set, adopted or taken away.
The device presented a key while it was held (waiting to be allowed, with no key of its own), and the first such key is kept: adopting its key takes that one, the key it was held with, not a later one.
What its latest message carried for a key.
When a message was last refused for carrying the wrong key, or none.
When its latest message came, as the instances that serve it know; null until it calls in.
Values captured from the endpoint’s path or topic template on the latest message it was let in on (its first, until then); used to address replies (e.g. MQTT reply topics).
object
The address its latest message came from, of those it was let in on (its first message, until it is let in; “” until it calls in). A message refused for the device’s status or rate moves nothing.
Whether a device may talk to the gateway: pending (known, waiting
for someone to allow or block it; its messages are refused meanwhile),
allowed (its messages are taken in) or blocked (its messages are
refused until someone allows it).
What other systems know the device by: system name to id.
object
The device’s own labels, by name: what a sync group’s placement rules pick members by, together with its endpoint’s labels (the device’s own win where both name one).
object
Free-form data from other systems, kept as given.
object
Example
{ "commands": [], "device": { "device": "CG0002", "endpoint": "office", "first_seen": null, "health": { "errors": 0, "messages": 0 }, "id": 43, "info": {}, "key": "none", "key_presented": "none", "key_refused_at": null, "labels": {}, "last_seen": null, "params": {}, "remote_ip": "", "status": "allowed" }}The endpoint is not known, the device id is not acceptable, the device is registered already, or the key is not acceptable or the package cannot build the commands that give it. A body that is not JSON is refused with 400, and one with an unknown field or a value of the wrong type with 422.
A refusal, and why.
object
Why the request was refused, in a sentence.
For a request whose parameters do not fit (422): what is wrong with each field. Absent otherwise.
What is wrong with one field of a request.
object
The parameter, as the request names it (values.volume for a
setting inside values).
What is wrong with it.
The request’s id, as its X-Request-Id header gives it: what to
quote when asking what happened to it.
Example
{ "error": "device 'CG0002' is already known on endpoint 'office'"}A login is configured and the request carries neither it nor an API token, or it carries a wrong login (WWW-Authenticate: Basic realm="Hour Advantage", no body). Or the request carries an API token that is not one (revoked, or never made), login or not (WWW-Authenticate: Bearer realm="Hour Advantage", error="invalid_token", the body the API token was refused).
Example
the API token was refusedHeaders
Section titled “Headers”The scheme to answer with: Basic realm="Hour Advantage", or for a refused token Bearer realm="Hour Advantage", error="invalid_token".
The Host header does not name a loopback address while one is required (no login configured, or the API listens on loopback), or the Origin header does not match the Host: {"error": ...} says which. Or no login is configured and the request carries Forwarded, X-Forwarded-For or X-Real-IP (a proxy forwarded it): the plain text body says so. Or an API token asks for a route its scope does not reach: the plain text body says so.
A refusal, and why.
object
Why the request was refused, in a sentence.
For a request whose parameters do not fit (422): what is wrong with each field. Absent otherwise.
What is wrong with one field of a request.
object
The parameter, as the request names it (values.volume for a
setting inside values).
What is wrong with it.
The request’s id, as its X-Request-Id header gives it: what to
quote when asking what happened to it.
Example
{ "error": "the Host must name this machine (localhost or a loopback address); an API reached by other names needs the admin login"}Example
a forwarded request needs the admin login; none is setMore than 2 admin logins are being checked at once: send the request again after the Retry-After seconds. A request carrying the login that checked out last, or an API token, is not held up.
Example
too many logins at once; try againHeaders
Section titled “Headers”Seconds to wait: 1.
Something went wrong in the gateway that asking again will not put right by itself; error says what.
A refusal, and why.
object
Why the request was refused, in a sentence.
For a request whose parameters do not fit (422): what is wrong with each field. Absent otherwise.
What is wrong with one field of a request.
object
The parameter, as the request names it (values.volume for a
setting inside values).
What is wrong with it.
The request’s id, as its X-Request-Id header gives it: what to
quote when asking what happened to it.
Example
{ "error": "db error: ERROR: permission denied for table settings"}The database cannot be used right now (not reachable, too busy, no connection free in time), or the instance is still starting: send the same request again shortly. An API token that cannot be checked for the same reason is answered 503 in plain text (the API token cannot be checked right now; try again shortly).
A refusal, and why.
object
Why the request was refused, in a sentence.
For a request whose parameters do not fit (422): what is wrong with each field. Absent otherwise.
What is wrong with one field of a request.
object
The parameter, as the request names it (values.volume for a
setting inside values).
What is wrong with it.
The request’s id, as its X-Request-Id header gives it: what to
quote when asking what happened to it.
Example
{ "error": "the gateway is starting; try again shortly"}