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.
Tenants and the install
Section titled “Tenants and the install”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)
Operation groups
Section titled “Operation groups”| Group | What it covers |
|---|---|
| tenants | Connect’s tenants: list, create, change, suspend, resume, stop and delete them. |
| setup | Listeners, 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). |
| packages | Package bundles: push a revision, activate one per line, look at what runs. Also a tenant’s policy packages, shared ones and adoptions. |
| devices | The device register, device keys and labels, actions and their commands, and the device messages that failed. |
| jobs | One action run over many devices, in waves. |
| sync | Sync groups: their settings, members, people, credentials, rows and change feed. Also routes and unrouted punches. |
| events | Stored events, read in order, and events other systems post. |
| instance | Traffic, the live stream, the wire capture, the instances, scenario runs. |
| attendance | Time 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). |
| probes | Liveness, readiness, health and metrics, for load balancers and monitoring. |
Authentication
Section titled “Authentication”| Rule | Detail |
|---|---|
| Login | With 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 tokens | Authorization: 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. |
| Revoking | DELETE /api/tokens/{name}. The instance that answers refuses the token at once. Every other instance does so within 60 seconds. |
| Address | Listening on any address other than loopback needs a login. The gateway does not start otherwise. |
| Host header | Must name a loopback address (localhost, 127.x.x.x, [::1]), unless the API listens off loopback with a login. |
| Origin header | When present, must match the Host header. |
| Proxies | Without 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.
# with the logincurl -u admin:password http://127.0.0.1:9090/api/tenants/default/devices# with an API tokencurl -H "Authorization: Bearer hadv_..." http://127.0.0.1:9090/api/tenants/default/devices# with an API tokenInvoke-RestMethod http://127.0.0.1:9090/api/tenants/default/devices -Headers @{ Authorization = "Bearer hadv_..." }Errors
Section titled “Errors”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" }]}| Status | Meaning |
|---|---|
| 400 | The request is not valid: a body that is not JSON, a value out of range, a reference to something that does not exist. |
| 401 | A login is configured and the request carries neither it nor an API token. Or it carries a token that is refused. |
| 403 | The Host or Origin header is refused. Or (without a login) the request was forwarded by a proxy. No JSON body. |
| 404 | What the path names does not exist. |
| 409 | The 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. |
| 413 | The request body is larger than 16 MiB. |
| 415 | A JSON body was sent without Content-Type: application/json. |
| 422 | The 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. |
| 429 | More logins are being checked at once than the gateway takes. Send it again after the Retry-After seconds. |
| 500 | Something failed in the gateway. The answer says only that, with the request_id. |
| 503 | The 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).
Requests and answers
Section titled “Requests and answers”-
Changes.
POSTadds,PATCHchanges,PUTsets,DELETEremoves.PATCHon listeners, endpoints, sinks, settings and sync groups is a JSON merge patch (RFC 7396). Objects merge,nullremoves, 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
afterandlimit(100 unless given, 1000 at most). They answernext, which you pass asafterfor the next page. Failures takebeforethe same way, newest first. Devices takeafter(<endpoint>/<device>of the last device of the page before) andlimit(1000 unless given, 10 000 at most). A page shorter thanlimitis 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-versionheader. 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.hourctlwaits 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
Warningheader, code 299. For example, a listener is added or changed onto a port no listener used before. It answers299 - "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, orlocalwithout a login.password,secretandkeyfields 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 withGET /api/auditorhourctl audit. -
Retries. A
POSTorPATCHsent with anIdempotency-Keyheader 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, withIdempotent-Replayed: true.hourctlsends every change under a key of its own. It sends it again when the answer says to try again (idempotency keys).
Sensitive values
Section titled “Sensitive values”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.
While an instance starts
Section titled “While an instance starts”Until an instance has reached and migrated its database, its admin listener answers only the probes:
/livezanswers 200./api/healthanswers with"starting": true./api/readyanswers 503.- Every other path answers 503
{"error": "the gateway is starting; try again shortly"}.
Actions
Section titled “Actions”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 endunanswered. This is for a device that is not coming back.
An action’s status:
| Status | Meaning |
|---|---|
queued | No step has been handed to the device yet. |
in_progress | Some steps have been handed out, and nothing has failed. |
done | Every step succeeded. |
failed | A step failed or went unanswered (failed_step, or gate_step for a gate). The steps after it that had not gone out were skipped. |
cancelled | Cancelled before every step had gone out. Those that had not were cancelled. |
timed_out | expires_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:
| Status | Meaning |
|---|---|
queued | Waiting to be handed to the device. |
offered | Written 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. |
succeeded | The device answered with success. |
failed | The device answered with failure. |
unanswered | Handed 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. |
cancelled | Taken back before it was handed out: its action was cancelled or expired. It never goes out. |
skipped | An earlier step of its action failed before this one was handed out. It never goes out. |
parked | Waiting 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.
Device keys
Section titled “Device keys”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
Section titled “hourctl”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:
export HOURADVANTAGE_ADMIN_TOKEN="$(hourctl token create ci)"$env:HOURADVANTAGE_ADMIN_TOKEN = hourctl token create ciAfter 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.