Actions
Everything sent to a device is an action: a list of steps the engine
tracks. Its steps go to the device in order, with one status, and a failed
step ends it there. The steps are either a named action’s or listed by the
caller (steps); each step is judged as it would be alone, and if any is
refused, nothing is queued. A named action is one of three things:
- a standard action, the gateway’s own vocabulary, the same for every vendor (below): a package maps each one it can to its device’s commands;
- one of the package’s own actions, for what the vocabulary has no word for (a firmware upgrade);
- one of the package’s commands, under its own name: an action of one step.
A caller lists its own steps with steps instead of action and params:
{ "steps": [{ "action": ..., "params": ... }, ...] }, each step
any of the three above. Their steps are queued one after another (a gate
stays a gate) as one action, named steps, with one id and one
action.result. A sensitive parameter is kept only as its size, under the
step it belongs to. hourctl action office CG0001 --steps @steps.json.
POST /api/tenants/{tenant}/devices/{endpoint}/{device}/actions
(hourctl action) queues one;
GET /api/tenants/{tenant}/devices/{endpoint}/{device} lists what a
device takes (available_actions, available_commands), and
hourctl device actions shows each with its parameters typed. To run one over many devices, in
waves, use a job. The API’s fields are in the Admin API page.
How actions go
- Every action and command declares its parameters, typed, and the request is checked against them before anything is queued: a parameter that is unknown, missing or out of range is answered 422 with what is wrong with each field, and nothing is queued. A parameter a device cannot honour is refused, never dropped: an action succeeds as asked or not at all.
- What an action writes (people, access, lists, settings, punches) is a sync domain: while the device’s sync group keeps that domain, sending the action straight to the device is refused (409); write through the sync group instead. An action carrying templates or photos of a person not allowed biometrics is refused (403; see biometrics).
- An action queues in a lane:
interactive(the default) orbulk, for large fills that may wait behind everything else. The gateway’s own work usesurgent(deletes, disables, biometric deletes) andsync. Commands go to a device by lane (urgent,interactive,sync,bulk), then oldest first, each action’s steps in order. - One action may be several commands, sent in order and together: many
actions go in one batch (every command waiting, up to 256 KiB of
payloads in one call: no count limits it, and what a device takes in one
message is its package’s to declare (
[commands] reply): the ZK package takes 200 commands andmax_command_bytesof them in a reply, the protocol’s limits), and no step waits for the answer to the one before it. A device that runs every command it is handed (ZK PUSH) runs every step of a batch even after one failed; steps not yet handed out when a failure is known are skipped. The action reports the first step that failed, with the device’s answer, and every step’s own status: fix what it names and send the action (or the failed part) again. Where a later step must not run unless an earlier one passed, the package makes the earlier one a gate (below). - An action given
expires_at(a job’stimeoutgives each device’s action one; with none, the action has no deadline) that has not had every step pass by then istimed_out, at that instant and not after it: what had not gone is cancelled, and what the device holds is given up on as an app’s give-up would (below): each step unanswered with itscommand.unansweredevent, and the action failed with them. - An action ends
done,failed,cancelledortimed_out, and anaction.resultevent says so once, with every step’s status and, unless it isdone, areason. Each step also has itscommand.result. - Steps are counted from 1, as people read them, everywhere they are
named: a hold’s and an action’s
reason(step 2 (add_card) failed: the device answered -5),failed_stepandgate_stepin the API,stepinaction.resultanddevice.heldevents, a job device’sdetail, andhourctl. - Sensitive parameters are shown only as their size, and their payload is kept sealed (where the install seals secrets) while the command is queued or offered, and only as its size once the command is over.
Lost commands
How long a device takes decides nothing: a command written into a reply to a device is offered (offered, counted,
with its age in the API), and stays so until its result comes or something says it is lost. A reply whose connection
closed changes nothing about it: the gateway does not guess from a connection whether the device had it. The engine keeps
facts only (what was handed out, and what was answered) and draws no conclusion from their order: a command is missed when
its package says so, and only these say a command is lost:
- Its package names it missed as it handles a message.
M.missed(req, in_hand, answered)is asked of every message that carries results, and of the requests of the routes listed in[commands] missed_on, while commands are in the device’s hand.in_handis the hand in the order it was handed out ({ id, action, writes }for each command),answeredthe ids of the results the message carries; it returnstrue(all of them), a list of ids, orfalse/nil (none). A command with an answer is answered, whatever is named: the ones the message answers are never marked missed. The rule is the protocol’s, so it lives in the package: a device that works through what it writes in order and answers in order is written as “a later one answered, so the earlier writes with no answer are missed”; one whose request says it restarted, as “what it held is missed”. - An action’s deadline (
expires_at) passes with it in the device’s hand: it is given up on, as below. - An app gives up on it:
DELETE .../actions/{id}?give_up=true(hourctl action cancel --give-up) cancels what has not gone out and gives up on the steps in the device’s hand. For a device that is not coming back.
A package that needs less than the whole hand declares the slice as data, and the engine reads only that: [commands.missed_hand]
with actions ("all", "writes" for the commands that write, or a list of command names) and up_to_answered (only the
commands handed out at or before the newest one the message answers). For a message that carries results, and is not on a
missed_on route, in_hand is then that slice: the commands of those actions and the ones the message answers, in the order they
were handed out. A message on a missed_on route, and every message of a package that declares nothing, is given the whole hand.
The declaration is the package’s claim that the slice is enough for its M.missed; the engine gives no meaning to “missed” and does
not change what M.missed is asked.
The ZK packages name the writes before a later answered one, and what a clock held when it asks for its options as it
starts (not what a CHECK in its hand explains, nor a reboot). BrightLink (MQTT) names the writes its device did not ack
before one it did, and, on its first heartbeat on a new broker connection ("birth": true: it has (re)subscribed), what was
pushed to it before and is not acked, a reboot excepted. A package with no M.missed has only the deadline and the
give-up: its commands stay in the device’s hand until it answers them.
A missed command whose package says handing it out again is safe (resend = "writes": the commands that declare what they
write) goes back in the queue, with the same id, and the device is handed it again, up to the number of times the package
declares (resend_times: a package that says resend = "writes" says how many). Missed once more than that, or not safe to hand
out again, it is unanswered: a command.unanswered event, and its action fails at it (Failed, a gate holds the
device). An answer that comes later still completes it.
Gates and holds
A package may make a step a gate (gate = true): one whose answer must
be in, and pass, before anything after it is sent. The steps before a
gate go first, the gate goes in a batch of its own, and nothing more goes
to the device until it has answered; the steps behind it wait (parked)
and go once it has passed, up to the next gate. Actions without gates go
as described above.
A gate that fails or goes unanswered fails the action there (gate_step,
and reason says what the device answered), drops the steps behind it,
and holds the device: nothing more is handed to it, on any lane, sync
included, until someone releases it
(POST /api/tenants/{tenant}/devices/{endpoint}/{device}/release, or
hourctl device release). What it sends is taken in as usual. Actions queued meanwhile
wait, and go once it is released; released with drop_queued
(--drop-queued), they are cancelled instead, each saying why. The hold
is shown on the device (held), with device.held and device.released
events. A gate that is cancelled or times out drops what is behind it too,
and holds nothing.
Asked again later
A device may answer that a step is not done yet, to be asked again in N
seconds (the package reads that in its answer and calls queue.retry):
the step waits (parked, retry_at) and the same command goes again once
the time has come, as often as the device asks, until the action expires:
it then times out. Its command.result carries retry_in. A step with
sensitive parameters cannot go again (only their size is kept once it
went): asked again, it fails.
The time asked for is the earliest the step goes again, not when it is delivered: a step can only be handed to a device when the device is next in contact. A device that polls (ZK PUSH, most HTTP clocks) gets it with its first poll after that time, so asked again in 5 seconds by a clock that polls every 15, it goes up to 15 seconds later.
Package actions
A package may offer actions of its own, for what the standard vocabulary
has no word for (a firmware upgrade, a vendor diagnostic). They go exactly
as the standard actions do (ordered steps, gates, asked again, the same
results and events), are listed with the device’s (available_actions,
hourctl device actions) and the package’s (standard = false),
and may be started by name and run by jobs. Each declares its parameters,
typed, and the sync domains it writes, as a command does:
M.actions = { firmware_upgrade = { description = "Loads a firmware image, applies it, and waits for the clock to come back.", params = { { name = "url", type = "string", required = true } }, writes = {}, expand = function(p) return { { action = "fw_upload", params = { url = p.url } }, { action = "fw_apply", gate = true }, -- nothing more goes unless it passed { action = "fw_version" }, -- answered "not yet" while rebooting } end, },}Writing packages says how to write one.
The standard actions
GET /api/tenants/{tenant}/actions lists them;
GET /api/packages/{name} what a package offers of them. Anything else a package offers is its own action or a
vendor command, under its own name.
user_idis always the user’s id on the device.keypad_pinis a secret code a user keys in; nothing here is calledpin.- A package’s own parameters for a standard action start with
x_(x_verify_mode) and are typed like any other. - Records are whole:
upsert_userreplaces the user, so a field left out is cleared on the device, not kept. - Device settings are set with
set_settings, by the names in the package’s settings registry (hourctl device options); there is no free key/value command.
Types: string is text; integer a whole number; boolean true or false;
wall time is the device’s wall-clock time (2026-10-01, 2026-10-01 08:30
or 2026-10-01 08:30:00); rfc3339 an instant with its offset; binary bytes
as base64 text; list of string a list of text (or text separated by
commas); cards a list of { number, format?, facility? } (or of numbers);
biometrics a list of templates as set_biometric takes them; object a JSON
object, as the parameter describes it.
hourctl pkg show <name> lists what a package offers of them.
People
upsert_user
Creates the user, or replaces their record. The record given is the whole user: a field left out is cleared or set to the device’s default, never kept from before. Templates and photo are not touched.
Writes: people.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s id on the device. |
name | string | The name shown on the device. |
role | user | enroller | admin | user (the default), enroller or admin. |
cards (sensitive) | cards | The user’s cards; none or an empty list: no card. |
password (sensitive) | string | A password the user may verify with. |
keypad_pin (sensitive) | string | A secret code the user may key in instead of badging. |
enabled | boolean | false: the user is kept but may not punch or open doors. |
valid_from | wall time | Device wall-clock time from which the user is valid. |
valid_to | wall time | Device wall-clock time until which the user is valid. |
groups | list of string | Access groups the user belongs to, as the device numbers them. |
delete_user
Removes the user and everything the device keeps for them (cards, templates, photo), as far as the device allows. Punches already taken stay.
Writes: people.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s id on the device. |
set_cards
Replaces the user’s cards and nothing else. An empty list takes them all away.
Writes: people.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s id on the device. |
cards (required, sensitive) | cards | The cards; an empty list: none. |
change_user_id
Gives a user a new id. Where the device cannot rename, this is a replace: punches under the old id are made sure of, the user is added under the new id with everything given, checked, the old id deleted and checked gone. The steps go out together, and a device may run them all even after one failed (the old id deleted though the new user was not added): the result names the failed step, and everything the new user is given is in the request, to be sent again.
Writes: people.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s current id. |
new_user_id (required) | string | The id the user is to have. |
name | string | The name shown on the device. |
role | user | enroller | admin | user (the default), enroller or admin. |
cards (sensitive) | cards | The user’s cards; none or an empty list: no card. |
password (sensitive) | string | A password the user may verify with. |
keypad_pin (sensitive) | string | A secret code the user may key in instead of badging. |
enabled | boolean | false: the user is kept but may not punch or open doors. |
valid_from | wall time | Device wall-clock time from which the user is valid. |
valid_to | wall time | Device wall-clock time until which the user is valid. |
groups | list of string | Access groups the user belongs to, as the device numbers them. |
biometrics (sensitive) | biometrics | The user’s templates, re-sent under the new id. Templates the device holds that are not given here are lost. |
jpeg_base64 (sensitive) | binary | The user’s photo, re-sent under the new id. |
punches_since | wall time | Device wall-clock time from which punches under the old id are made sure of first (default: a day ago). |
allow_reenroll | boolean | true: go ahead although templates the device may hold under the old id are not given and will have to be enrolled again. |
set_biometric
Stores a template captured elsewhere, as a biometric event carries it. Templates are not converted: the device must take the format.
Writes: people.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s id on the device. |
kind (required) | fingerprint | face | palm | finger_vein | fingerprint, face, palm or finger_vein. |
index | integer | Which template: the finger (0-9), or the part or slot. |
template (required, sensitive) | binary | The template. |
format | string | The template’s format, ” |
valid | boolean | false: store it switched off. |
delete_biometrics
Removes one template (kind and index), every template of a kind (kind), or all of the user’s templates.
Writes: people.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s id on the device. |
kind | fingerprint | face | palm | finger_vein | Only this kind. |
index | integer | Only this template of the kind. |
enroll_biometric
Starts enrolment on the device for someone standing at it. The template arrives as a biometric event if the endpoint collects biometrics.
Writes no sync domain.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s id on the device. |
kind (required) | fingerprint | face | palm | finger_vein | What to enroll. |
index | integer | Which finger (0-9) or slot. |
set_user_photo
The photo the device shows (or enrols a face from, where it does).
Writes: people.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s id on the device. |
jpeg_base64 (required, sensitive) | binary | The JPEG. |
delete_user_photo
Removes the user’s photo.
Writes: people.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s id on the device. |
query_users
The device sends its user records again, as user events: one user, or all of them.
Writes no sync domain.
| parameter | type | |
|---|---|---|
user_id | string | Only this user. |
clear_users
Deletes every user, with their cards, templates and photos.
Writes: people.
No parameters.
rename_user
Gives a user a new id in place, keeping everything the device holds for them. Only devices that can rename offer it; elsewhere an id change is a replace (change_user_id).
Writes: people.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s current id. |
new_user_id (required) | string | The id the user is to have. |
Punches
query_punches
The device sends the punches it holds in the range again, as punch events with the same ids.
Writes no sync domain.
| parameter | type | |
|---|---|---|
from | wall time | Device wall-clock time of the first punch. |
to | wall time | Device wall-clock time of the last punch; a date alone: its end. |
clear_punches
Deletes the punches the device holds: all of them, or those up to a time.
Writes no sync domain.
| parameter | type | |
|---|---|---|
until | wall time | Only punches at or before this device wall-clock time. |
set_punch_state
Tells the device a user’s latest punch elsewhere, so it can enforce lock-out or anti-passback itself.
Writes: punches.
| parameter | type | |
|---|---|---|
user_id (required) | string | The user’s id on the device. |
time (required) | rfc3339 | When the user last punched. |
state_name | string | The punch’s state (check_in, …). |
work_code | string | The punch’s work code. |
lockout_until | rfc3339 | Until when the user may not punch again. |
zone | string | The anti-passback zone the punch was in. |
inside | boolean | The user is now inside the zone. |
Device
sync_time
Sets the device’s clock: to the given instant, or to now.
Writes no sync domain.
| parameter | type | |
|---|---|---|
time | rfc3339 | The time to set; default: when the device is given it. |
reboot
Restarts the device.
Writes no sync domain.
No parameters.
wipe
Removes the data the gateway manages on the device: the people with their cards, credentials and photos, the punches, and the access and list data (schedules, holidays, access groups, work codes, messages). Every network and server setting, and the device’s other settings, are kept, so the device stays connected to the gateway: it is left as a fresh member, ready to be filled again. Where a device has no command for a part, the package’s description of the action says what stays.
Writes: people, access, lists.
No parameters.
get_info
The device reports what it is (firmware, model, counts); the device record’s info is updated.
Writes no sync domain.
No parameters.
open_door
Unlocks a door for a moment.
Writes no sync domain.
| parameter | type | |
|---|---|---|
door | string | Which door, as the device numbers them; default: its only one. |
seconds | integer | How long; default: the device’s own unlock time. |
show_message
Shows a message on the device’s screen: to everyone, or to one user when they verify.
Writes: lists.
| parameter | type | |
|---|---|---|
text (required) | string | The message. |
user_id | string | Only to this user; default: everyone. |
from | wall time | Device wall-clock time it starts showing; default: now. |
minutes | integer | How long it shows. |
Lists
set_list_item
Adds or replaces an item of one of the device’s lists (work, job and tip codes, messages).
Writes: lists.
| parameter | type | |
|---|---|---|
list (required) | work_code | job_code | tip_code | message | work_code, job_code, tip_code or message. |
key (required) | string | The item’s code or number. |
fields (required) | object | Its fields: name (codes); text, user_ids, from and minutes (messages). |
delete_list_item
Removes an item of one of the device’s lists.
Writes: lists.
| parameter | type | |
|---|---|---|
list (required) | work_code | job_code | tip_code | message | work_code, job_code, tip_code or message. |
key (required) | string | The item’s code or number. |
set_work_code
A code users may pick or key in with a punch (work, job or labour code).
Writes: lists.
| parameter | type | |
|---|---|---|
code (required) | string | The code. |
name | string | Its name. |
delete_work_code
Removes a work code.
Writes: lists.
| parameter | type | |
|---|---|---|
code (required) | string | The code. |
Access
set_schedule
Adds or replaces a schedule: when in each day of the week it allows access. A schedule the device cannot hold as given (more intervals a day than it has) is refused, never cut.
Writes: access.
| parameter | type | |
|---|---|---|
slot (required) | integer | The schedule’s number on the device. |
name | string | Its name. |
days | object | Each day (sun, mon, tue, wed, thu, fri, sat) as a list of [“HH:MM”, “HH:MM”] intervals; a day left out allows nothing. |
holiday | list of string | Holidays (their slots) on which the schedule applies too. |
delete_schedule
Removes a schedule, or puts it back to the device’s default where it cannot be removed.
Writes: access.
| parameter | type | |
|---|---|---|
slot (required) | integer | The schedule’s number on the device. |
set_holiday
Adds or replaces a holiday: days on which holiday schedules apply.
Writes: access.
| parameter | type | |
|---|---|---|
slot (required) | integer | The holiday’s number on the device. |
name | string | Its name. |
from (required) | wall time | Its first day. |
to | wall time | Its last day; default: the first. |
type | string | The device’s holiday type, where it has them. |
delete_holiday
Removes a holiday.
Writes: access.
| parameter | type | |
|---|---|---|
slot (required) | integer | The holiday’s number on the device. |
set_access_group
Adds or replaces an access group: the schedules and doors its members may use.
Writes: access.
| parameter | type | |
|---|---|---|
slot (required) | integer | The group’s number on the device. |
name | string | Its name. |
schedules | list of string | Its schedules (their slots). |
doors | list of string | The doors it opens; none: all. |
delete_access_group
Removes an access group.
Writes: access.
| parameter | type | |
|---|---|---|
slot (required) | integer | The group’s number on the device. |
Settings
set_settings
Sets device settings from the package’s settings catalog, by name, all at once.
Writes: settings.
| parameter | type | |
|---|---|---|
values (required) | object | The settings, { name: value }, typed as the catalog says. |
read_settings
The device reports its settings (a settings.report event).
Writes no sync domain.
| parameter | type | |
|---|---|---|
names | list of string | Only these settings; default: all. |