Skip to content

Admin API

The admin API runs and changes the gateway while it runs. It listens on the admin address (127.0.0.1:9090 by default, HOURADVANTAGE_ADMIN_LISTEN), never on a device listener’s port. It takes and answers JSON. hourctl is a client of this API. hourctl --json prints the API’s answers.

Every operation is in the endpoint reference. That reference has its parameters, request and answer bodies, examples and errors. The same description is served as OpenAPI 3.1 at GET /api/openapi.json. It uses the same login as the rest. It is for OpenAPI viewers, client generators and AI agents. The same file is also on this site at /openapi.json, with no login, so you can read it without a server.

One install serves many tenants. What is a Connect tenant’s is under /api/tenants/{tenant}/. That covers:

  • its listeners, endpoints, sinks, sync groups, devices and jobs
  • vars and secrets
  • its policy packages and adoptions
  • events, and the events posted into it
  • failures, traffic, the wire capture and the live stream
  • its setup export

A fresh install has the tenant default. Time and Attendance keeps tenants of its own, under /api/attendance/tenants/{tenant}/.

What is the install’s is under /api/ directly:

  • the tenants themselves (/api/tenants)
  • the install-level sinks (/api/sinks)
  • settings and the log level
  • protocol packages and shared policy packages (/api/packages/shared)
  • tokens
  • the audit trail
  • the instances
  • the whole install’s export (/api/export)
GroupWhat it covers
tenantsConnect’s tenants: list, create, change, suspend, resume, stop and delete them.
setupListeners, endpoints, sinks and their deliveries, settings, the log level, vars and secrets, API tokens, the audit trail, the setup export and this description (/api/openapi.json).
packagesPackage bundles: push a revision, activate one per line, look at what runs. Also a tenant’s policy packages, shared ones and adoptions.
devicesThe device register, device keys and labels, actions and their commands, and the device messages that failed.
jobsOne action run over many devices, in waves.
syncSync groups: their settings, members, people, credentials, rows and change feed. Also routes and unrouted punches.
eventsStored events, read in order, and events other systems post.
instanceTraffic, the live stream, the wire capture, the instances, scenario runs.
attendanceTime and Attendance, where the instance runs it. Its tenants, and for each tenant: ledgers, facts, who waits to be worked out again, setup, policy layers and packages (guide).
probesLiveness, readiness, health and metrics, for load balancers and monitoring.
RuleDetail
LoginWith HOURADVANTAGE_ADMIN_USERNAME and HOURADVANTAGE_ADMIN_PASSWORD_HASH set, every request needs HTTP Basic auth with that login, or an API token. Without a login, no authentication is asked for. The API is then reachable from the same machine only.
API tokensAuthorization: Bearer hadv_... (RFC 6750). Make one with POST /api/tokens or hourctl token create <name>. The secret is shown once. An install token can do everything the login can. A token scoped to a tenant (connect:<tenant> or attend:<tenant>) reaches only that tenant’s routes in that engine (tokens). Tokens start hadv_. A revoked or unknown token is refused with 401, whether a login is configured or not.
RevokingDELETE /api/tokens/{name}. The instance that answers refuses the token at once. Every other instance does so within 60 seconds.
AddressListening on any address other than loopback needs a login. The gateway does not start otherwise.
Host headerMust name a loopback address (localhost, 127.x.x.x, [::1]), unless the API listens off loopback with a login.
Origin headerWhen present, must match the Host header.
ProxiesWithout a login, a request carrying Forwarded, X-Forwarded-For or X-Real-IP is refused. Set a login to put the API behind a reverse proxy.
Probes/livez, /api/health and /api/ready need no login and skip every check above. /metrics needs the login or an install token (metrics).

The login comes first. It makes the first API token, and it is what lets the API listen off loopback.

Terminal window
# with the login
curl -u admin:password http://127.0.0.1:9090/api/tenants/default/devices
# with an API token
curl -H "Authorization: Bearer hadv_..." http://127.0.0.1:9090/api/tenants/default/devices
Terminal window
# with an API token
Invoke-RestMethod http://127.0.0.1:9090/api/tenants/default/devices -Headers @{ Authorization = "Bearer hadv_..." }

A refused request answers {"error": "..."}, saying why. Some requests have action or command parameters that do not fit what the package declares. Such a request also lists each wrong field, and nothing is queued:

{
"error": "action 'upsert_user': parameter 'user_id' is required",
"fields": [{ "field": "user_id", "message": "is required" }]
}
StatusMeaning
400The request is not valid: a body that is not JSON, a value out of range, a reference to something that does not exist.
401A login is configured and the request carries neither it nor an API token. Or it carries a token that is refused.
403The Host or Origin header is refused. Or (without a login) the request was forwarded by a proxy. No JSON body.
404What the path names does not exist.
409The request conflicts with the current state: a listener still used by an endpoint, an id already taken, a job command that does not apply to the job as it is, an Idempotency-Key whose first request is still running.
413The request body is larger than 16 MiB.
415A JSON body was sent without Content-Type: application/json.
422The body’s fields do not fit its shape (a missing or unknown field, a wrong type). Or action or command parameters do not fit what is declared (fields says which). Or an Idempotency-Key was sent before with another request.
429More logins are being checked at once than the gateway takes. Send it again after the Retry-After seconds.
500Something failed in the gateway. The answer says only that, with the request_id.
503The database cannot be used right now (not reachable, or too busy to give a connection in time). Or the instance is still starting. Send the same request again shortly.

A 500 or 503 does not say what failed inside. It leaves out the database’s words, a query, a file path and whose data it was. That is written to the log, on an a request failed line under the same request id. A refusal (4xx) says why the request was refused.

Each operation’s page lists the statuses it can answer and when. Every answer carries an X-Request-Id. An error body names it too (request_id). Give it when you report a problem (request ids).

  • Changes. POST adds, PATCH changes, PUT sets, DELETE removes. PATCH on listeners, endpoints, sinks, settings and sync groups is a JSON merge patch (RFC 7396). Objects merge, null removes, arrays and other values replace. A change is checked in full and applied completely or not at all. Every instance sharing the database follows it.

  • Write-only values. Passwords, webhook secrets and package secrets are never answered with. Answers say only whether one is set (password_set, secret_set).

  • Paging. Lists that can grow without bound are read a page at a time. Events and the audit trail take after and limit (100 unless given, 1000 at most). They answer next, which you pass as after for the next page. Failures take before the same way, newest first. Devices take after (<endpoint>/<device> of the last device of the page before) and limit (1000 unless given, 10 000 at most). A page shorter than limit is the last.

  • Config version. Some changes are put into use by every instance from memory. A change like that answers with the config version it made, in a houradvantage-config-version header. These changes are:

    • listeners, endpoints, sinks, settings and sync group settings
    • a stop or start
    • a package revision activated
    • a var or secret set or deleted
    • a device’s status, keys or registration

    Every instance reports the version it has applied in GET /api/peers. hourctl waits for all of them, or for each to refuse the change and say why, and says how far they got (config versions).

  • Warnings. A change that leaves something for you to do answers with a Warning header, code 299. For example, a listener is added or changed onto a port no listener used before. It answers 299 - "port 8081 is one no listener of this setup used before: a load balancer or a published port that clocks reach it by needs it too (...)". Exposing ports is deploy config (adding a port).

  • Audit trail. Every change that succeeds is recorded with who made it. That means every method but GET. It leaves out scenario runs, events posted to a tenant, shift-cost calculations and calls between instances. Who made it is the login’s user name, token:<name> for an API token, or local without a login. password, secret and key fields are removed first. A secret’s value is never recorded. Sensitive parameters are kept as their size. Each entry keeps the request’s id. Read it with GET /api/audit or hourctl audit.

  • Retries. A POST or PATCH sent with an Idempotency-Key header is done once, however often it is sent. This holds for 24 hours, on whichever instance it reaches. The same key with the same request is answered as the first was, with Idempotent-Replayed: true. hourctl sends every change under a key of its own. It sends it again when the answer says to try again (idempotency keys).

Parameters that an action or command marks sensitive are answered, listed, streamed and audited only as "<redacted N bytes>". Examples are passwords, keypad PINs, card numbers, templates, photos and keys. The payload of a command that has any is redacted the same way. The device gets the real payload.

While it waits, the payload is sealed in the database when HOURADVANTAGE_SECRET_KEY is set (secrets at rest). It stays sealed while the command is queued or offered (it may be offered again). Once the command is over (answered, unanswered, cancelled or skipped), the stored payload is replaced by its size.

If the package marks a command’s answer sensitive (sensitive_result), the command keeps its result only as "<redacted N bytes>", with no result_base64. An example is a file fetched from the clock. The answer goes whole to the sinks in its command.result event.

Until an instance has reached and migrated its database, its admin listener answers only the probes:

  • /livez answers 200.
  • /api/health answers with "starting": true.
  • /api/ready answers 503.
  • Every other path answers 503 {"error": "the gateway is starting; try again shortly"}.

An action is an ordered group of commands (its steps) for one device. It is a standard action, one of the package’s own actions, or one of the package’s commands (an action of one step). The device’s package turns it into its commands. How actions go out, gates and holds, and steps asked again later are explained in actions.

The operations are:

  • queue an action
  • list actions
  • get one
  • cancel one. With give_up=true, it also gives up on the steps already in the device’s hand that it has not answered. They end unanswered. This is for a device that is not coming back.

An action’s status:

StatusMeaning
queuedNo step has been handed to the device yet.
in_progressSome steps have been handed out, and nothing has failed.
doneEvery step succeeded.
failedA step failed or went unanswered (failed_step, or gate_step for a gate). The steps after it that had not gone out were skipped.
cancelledCancelled before every step had gone out. Those that had not were cancelled.
timed_outexpires_at passed before every step had passed. At that instant, those that had not gone out were cancelled. Those in the device’s hand were given up on (unanswered, each with its event). An action with no expires_at never times out.

Each step is a command, with its own status:

StatusMeaning
queuedWaiting to be handed to the device.
offeredWritten into a reply to the device. No answer yet. The device may or may not have it. A reply that went nowhere is no different from one that arrived. So it stays offered until the device’s result, a loss, or a give-up.
succeededThe device answered with success.
failedThe device answered with failure.
unansweredHanded out and lost. Its package named it missed (M.missed: a later write was answered, or the device restarted). Or you gave up on it (give_up). Or its action’s expires_at passed. Or it was handed out twice, for a command that is handed out once more. A command.unanswered event is sent once. A late answer still completes it. Never because of how long it took.
cancelledTaken back before it was handed out: its action was cancelled or expired. It never goes out.
skippedAn earlier step of its action failed before this one was handed out. It never goes out.
parkedWaiting behind a gate of its action that has not passed, or asked to be sent again later (retry_at).

Step numbers (failed_step, gate_step) count from 1. A device’s commands are handed to it at most once each. At most 10 000 commands wait per device. The clock’s answer arrives as result_code, result (or result_base64 when it is not text) and as a command.result event. When the action ends, an action.result event (events) says how, once.

Devices covers three things. One is a device’s key state (none, pending, active). One is how to set, remove or adopt a key with PATCH /api/tenants/{tenant}/devices/{endpoint}/{device}. One is what a refused device is answered.

hourctl is a client of this API. Each subcommand makes one or a few of these calls, and --json prints the API’s answer. Every subcommand and option is in the command-line reference.

The variables and flags that tell hourctl where the API is and how to log in are listed under environment. hourctl token create <name> prints the new token’s secret alone, so you can capture it:

Terminal window
export HOURADVANTAGE_ADMIN_TOKEN="$(hourctl token create ci)"
Terminal window
$env:HOURADVANTAGE_ADMIN_TOKEN = hourctl token create ci

After a change, hourctl waits for every instance to apply the config version it made, or to refuse it and say why. It says how far they got. It does not give up after a time. While it waits, it says who it is waiting for. hourctl pkg push --activate and hourctl pkg activate wait in the same way for every instance to run the revision. They print a line such as [email protected]: revision 7 runs on 3/3 instances, and exit non-zero naming any instance that refused it. An instance whose session with the database ends is no longer in the list, so it is no longer waited for.