Give a machine its own API key, step by step
Let another system call Codossier Office as itself, with exactly the access you give it, using a key that is shown once, kept in your vault, revoked in one step and never silent when it fails.
A machine signs in as its own service account with a key shown once, scoped by roles, revoked in one step and never silent when refused.
What it is
- A service account is a user that is not a person: no password, no authenticator and no default role. It is listed in Builder → Users.
- ApiKeyIssue, run by a Global Administrator on the service account, answers a new key once, with an optional expiry of up to 3,650 days. Codossier Office keeps only a fingerprint of the key.
- The machine sends
Authorization: Bearerand the key on every call, and acts with exactly the service account's roles. - Keys are records of the API Keys table: deactivate one to revoke it, or turn the account off to stop all its keys.
Good to know
- Never send a key by email or chat: put it straight into your secrets vault, and give each machine its own.
- Codossier Office refuses keys for people, for deactivated accounts and for its own agents.
- A refused key (unknown, revoked, expired, or its account inactive) is refused with 401, kept on a list for a day and emailed to the office's admin alert address, naming the account but never the key.
Before you start
- A person signs in with a password and a second factor. A machine cannot, so it gets a service account (a user that is not a person) and an API key, which it sends on every call as
Authorization: Bearer. The key acts with exactly the service account's roles: nothing more. - The example sets up the billing system of an invented firm: a service account Ledgerline Billing Sync, a key for it that lapses after a day, one call with the key, and the key revoked. The key itself is never shown on this page, not even in part.
1The service account: Builder → Users
A service account is a user with Service account set: it has no password and no authenticator, and nobody signs in as it in a browser. Here Ledgerline Billing Sync is in Builder → Users like everyone else; turning it off with its switch stops every key it holds at once.
A new service account gets no role by itself (a person gets the office's default role): give it only what the machine needs.

2Create the service account through the API
An administrator creates it as any user: POST /api/v1/data/user with a name, a username in the form of an address, is_service_account set to true and a description of what it is for. Codossier Office answers 201 with its id.

3Issue a key: ApiKeyIssue, answered once
A Global Administrator issues the key with the operation ApiKeyIssue on the service account: POST /api/v1/execute/ApiKeyIssue/user/{id}, with a name for the key and, if it should lapse, expires_days (here 1; at most 3,650). Leave it out for a key that does not expire.
The answer holds the key in api_key, once: Codossier Office keeps only a fingerprint of it and can never show it again. Put it straight into your secrets vault and give the machine access to it there. On this page the key and its prefix are hidden.

4Call with the key
The machine sends the key on every request: Authorization: Bearer and the key. Here it reads the catalogue's version, which any signed-in caller may. Codossier Office notes when each key was last used.
Everything else the key may do is what the account's roles allow. With no role yet, its read of the hearings came back empty: Read and write records over the API, last step.

5Revoke the key: the API Keys list
Keys are records of the API Keys table (open it from the table search, or at /api_key). Each shows its Service Account, Expires On and Last Used On. To revoke a key, deactivate its record; it then appears under Inactive API Keys, as this one does. A revoked key stops working within a minute.
Revoke a key the moment you no longer need it, and issue a new one rather than sharing one key between two machines.

6Revoke through the API, and what a refused call looks like
The same revocation from a script: PATCH /api/v1/data/api_key/{id} with state_id false and status_id 0; Codossier Office answers 204. Deactivating the service account instead stops all its keys at once.
Below, a call with no key at all: 401, auth_required. A revoked, expired or unknown key is refused with 401 too (API key not accepted), and never silently: Codossier Office keeps a list of refused keys for the last day and emails the office's admin alert address, naming the key's account but never the key.

What next
- What the key may do is what the account's roles allow: Set what a role reaches and Choose who may run which operation.
- Then call the API with it: Find and call any operation, Read and write records over the API.