Call the API
Sign a script in as a realm administrator, find the address of every product's API on your realm's host, and follow the paging, revisions and errors every call shares.
AvailableAPIRFC 9110, RFC 7396, RFC 9457
Everything the dashboard does, it does through your realm’s APIs, and a script can make the same calls. Some settings are set through the API alone, and their pages show the call. This page is what every one of those pages assumes: where each API lives, how to get the session the calls carry, and the rules every call follows.
Every call on this site is written on your realm’s own host, https://foobar.cvyuh.com, where foobar stands for
your realm. Put your realm’s host in its place.
Before you begin
Section titled “Before you begin”- An account with the rights the calls need. A user in a group that holds a privilege in the realm:
RealmOwnerto change anything,RealmViewerto read, or a role of your own. See Delegated administration. - A sign-in chain a script can answer: a name, a password, and if you like a code from an authenticator app.
curl, andjqto script the calls.
Where each API lives
Section titled “Where each API lives”| Product | Base |
|---|---|
| Directory, sign-in settings, policies, agents, keys, sessions, privileges | https://foobar.cvyuh.com/api/v0/am |
| Realms (create and manage sub-realms) | https://foobar.cvyuh.com/api/v0/am/global/realms/v1 |
| Secrets Store, managed vaults | https://foobar.cvyuh.com/api/v0/vault/managed/v1 |
| Secrets Store, sealed vaults | https://foobar.cvyuh.com/api/v0/vault/sealed/v1 |
| Endpoint Management: devices | https://foobar.cvyuh.com/api/v0/endpoint/ppm/v1 |
| Detection & Response: security log, response | https://foobar.cvyuh.com/api/v0/endpoint/dar/v1 |
| AI Governance: the AI fleet | https://foobar.cvyuh.com/api/v0/endpoint/aig/v1/api/v1 |
| Apps and agents: OAuth 2.0, OpenID Connect | https://foobar.cvyuh.com/oauth2/… |
| Gateway and enforcement points: policies, decisions | https://foobar.cvyuh.com/policies/v1, https://foobar.cvyuh.com/access/v1 |
The administration APIs (every row but the last two) take a realm administrator’s session. The last two are called by apps, agents and enforcement points with credentials of their own, as their standards say: see Apps and agents.
Each product’s API reference lists every endpoint it serves, by area: each is listed in Develop.
Get a session
Section titled “Get a session”The administration APIs take one credential: a session, the same kind the dashboard holds after you sign in. A
script gets one by signing in the way the dashboard does, as a user who holds a realm administrator’s rights, and
sends it as a cookie on every call. Every page on this site writes it as $CVYUH_SESSION.
-
Start a sign-in. Post an empty body. The realm runs its default sign-in chain and answers with the first page of prompts, and an
authIdthat names this sign-in:Terminal window curl -X POST https://foobar.cvyuh.com/api/v0/am/auth/v1/authenticate \-H "Content-Type: application/json" \-d '{}'{"authId": "<auth id>","header": "Sign in","prompts": [{ "kind": "name", "output": [{ "name": "prompt", "value": "User name" }], "input": [{ "value": "" }] },{ "kind": "password", "output": [{ "name": "prompt", "value": "Password" }], "input": [{ "value": "" }] }]} -
Answer the prompts. Send the
authIdback, with each prompt’skindand your answer in itsinput:Terminal window curl -X POST https://foobar.cvyuh.com/api/v0/am/auth/v1/authenticate \-H "Content-Type: application/json" \-d '{"authId": "<auth id>","prompts": [{ "kind": "name", "input": [{ "value": "maya" }] },{ "kind": "password", "input": [{ "value": "<password>" }] }]}'If the chain has another step, such as a code from an authenticator app (
kindcode), the answer is the next page with a newauthId: answer it the same way. When the chain is done, the answer carries the session astokenId:{ "tokenId": "<session>", "successUrl": "<url>" } -
Keep the session in
CVYUH_SESSION.Terminal window export CVYUH_SESSION="<session>" -
Check it works.
whoamianswers who you are, your roles in the realm, and how long the session has left (session.expiresInSecs):Terminal window curl -X POST https://foobar.cvyuh.com/api/v0/am/whoami/v1 \-H "Cookie: x-cvyuh-token=$CVYUH_SESSION"
A wrong password answers 401 with the code INVALID_CREDENTIALS; a sign-in left too long between steps answers
408 with LOGIN_TIMEOUT, and you start again from step 1.
In a script, with jq, the two steps of a name-and-password chain are:
AUTH_ID=$(curl -s -X POST https://foobar.cvyuh.com/api/v0/am/auth/v1/authenticate \ -H "Content-Type: application/json" -d '{}' | jq -r .authId)
export CVYUH_SESSION=$(curl -s -X POST https://foobar.cvyuh.com/api/v0/am/auth/v1/authenticate \ -H "Content-Type: application/json" \ -d "{\"authId\":\"$AUTH_ID\",\"prompts\":[ {\"kind\":\"name\",\"input\":[{\"value\":\"maya\"}]}, {\"kind\":\"password\",\"input\":[{\"value\":\"$PASSWORD\"}]}]}" | jq -r .tokenId)To end the session:
curl -X POST https://foobar.cvyuh.com/api/v0/am/auth/v1/logout \ -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"Sessions in scripts
Section titled “Sessions in scripts”A script’s session is the same thing as the dashboard’s. It carries the rights of the account it signed in with,
decided by Delegated administration, and follows the realm’s
Sessions settings: it ends after
maxSessionMinutes (120 by default) or after maxIdleMinutes unused (30 by default), and wrong passwords count
toward a lockout. The dashboard keeps its session in a cookie the page’s own scripts can’t read, so a script signs in
on its own rather than borrowing it.
Plan a script around three facts:
- Sign in once per run, and reuse the session. One user holds at most
sessionQuotasessions (10 by default), and a sign-in past that ends the user’s oldest. A script that signs in on every call ends its own earlier sessions, and the dashboard’s. End the session withlogoutwhen the run is done. - Give scripts their own account. A user of their own, in a group with only the rights the script needs, keeps its sessions apart from a person’s and its actions apart on the audit trail.
- Use a chain a script can answer. A script can answer a name, a password and an authenticator-app code. It can’t use a passkey, so the script’s account must have none.
Protect a script’s account
Section titled “Protect a script’s account”A script’s account can do whatever its group may, for as long as its session lasts, and the admin APIs don’t take an app’s own credentials yet. Treat its password as you would an administrator’s:
- Give it the least it needs. Put the account in a group of its own, and grant that group
RealmViewerif the script only reads, or a role of your own that covers only what it changes. NeverRealmOwnerfor a script that doesn’t need it. - Keep its password in a secret store, such as a vault in the Secrets Store or your CI system’s secrets, and read it into the script at run time. Never in the script, a repository or a command line.
- Add an authenticator-app code. Register an authenticator for the account, keep its secret in the same store,
and have the script compute each code (for example with
oathtool --totp -b "$TOTP_SECRET"). A stolen password alone then gets nowhere. - Keep its sessions short. A script’s session follows the realm’s Sessions settings: sign in at the start of a run and sign out at the end.
- Watch it. The account’s sign-ins and its changes are on the audit trail under its own name: see Read a user’s or agent’s trail.
Wrong passwords count toward the account’s lockout like anyone’s, so a script with a stale password locks its own account out. Fix the password before running it again.
Conventions
Section titled “Conventions”Objects and settings
Section titled “Objects and settings”Under https://foobar.cvyuh.com/api/v0/am, every setting and object is read and written the same way. Each has a
type, and each object an id:
| Call | What it does |
|---|---|
GET /api/v0/am/objects/v1/<type> | List the objects of a type, one page at a time |
POST /api/v0/am/objects/v1/<type>?id=<id> | Create one; leave out id and the realm picks one |
GET /api/v0/am/objects/v1/<type>/<id> | Read one |
PUT /api/v0/am/objects/v1/<type>/<id> | Replace it whole |
PATCH /api/v0/am/objects/v1/<type>/<id> | Change only the fields you send |
DELETE /api/v0/am/objects/v1/<type>/<id> | Delete it |
GET /api/v0/am/objects/v1/<type>/<id>/history | Its changes, newest first |
GET /api/v0/am/types/v1 | The realm’s types and their schemas |
Reading the user maya:
curl https://foobar.cvyuh.com/api/v0/am/objects/v1/user/maya \ -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"A realm setting such as sessionSettings is a type with one object, whose id is the type’s name:
https://foobar.cvyuh.com/api/v0/am/objects/v1/sessionSettings/sessionSettings. A setting you never set takes its
default, and a read shows every setting with its default filled in.
Paging and filters
Section titled “Paging and filters”A list answers one page: data, with page, pageSize, totalCount and totalPages.
pagecounts from 1.pageSizeis 20 by default and 100 at most.filteris a JSON search document:textfor a free-text match, andfilterfor a tree of conditions, such as{"filter":{"field":"status","op":"=","value":"inactive"}}. Encode it for a URL. See Search and paging for the full grammar.sortnames a field, with-before it for descending:?sort=-createTime.totalPolicy=noneskips the count, for a faster answer on a large list.cursorpages by a continuation instead: the answer carrieshasMoreandnextCursor, and you sendnextCursorback ascursorfor the next page.expandnames the links to include:?expand=memberOffor a user’s group links,?expand=memberOf/*for the groups themselves.
curl "https://foobar.cvyuh.com/api/v0/am/objects/v1/user?pageSize=50&sort=-createTime&expand=memberOf" \ -H "Cookie: x-cvyuh-token=$CVYUH_SESSION"Where a filter is too long for an address, send the same request with the method QUERY and the parameters as a
JSON body. The security log’s lists are POSTs that take the same page, pageSize, sort and filter in the body.
Revisions and If-Match
Section titled “Revisions and If-Match”Every object carries a revision, rev, in its body and as its ETag. Send it back in If-Match, and the write
applies only if no one has changed the object since you read it:
curl -X PATCH https://foobar.cvyuh.com/api/v0/am/objects/v1/sessionSettings/sessionSettings \ -H "Cookie: x-cvyuh-token=$CVYUH_SESSION" \ -H 'If-Match: "<rev>"' \ -H "Content-Type: application/json" \ -d '{ "maxIdleMinutes": 15 }'| You send | The realm |
|---|---|
If-Match: "<rev>" that matches | Applies the write |
If-Match: "<rev>" that doesn’t match | Answers 412: read the object again and retry |
If-Match: * | Applies the write if the object exists, whatever its revision |
No If-Match | Applies it, unless the type requires a revision: then 428 |
If-None-Match: * on a PUT | Creates the object only if it doesn’t exist yet, and answers 412 if it does |
Only the header counts: a rev in the body is not a precondition. The Secrets Store has its own check-and-set,
options.cas, described in Check-and-set.
Lists replace, maps merge
Section titled “Lists replace, maps merge”A PATCH with a JSON object is a merge (RFC 7396): the fields you send change, and the rest keep their values.
Inside it, a list and a map behave differently.
- A map is merged key by key into the stored one, such as a realm’s
scopeClaims. A key sent asnullis removed, and goes back to its default if it has one. - A
PATCHwhose body is a JSON array is a list of RFC 6902 operations (add,remove,replace, …), for a change to one item of a list without sending the rest. - Every write’s body is JSON, sent as
Content-Type: application/json. Anything else answers415.
Secrets Store answers
Section titled “Secrets Store answers”The Secrets Store answers its content under data, and a change with nothing to report answers 204. It answers
409 (DISABLED) until a realm administrator turns it on. The ways to name each owner’s vault are in
Vaults.
Field names
Section titled “Field names”Field names are camelCase (redirectUris, maxIdleMinutes, validTo) on every administration API, with two
exceptions:
- The OAuth 2.0 and OpenID Connect endpoints under
https://foobar.cvyuh.com/oauth2/use the standards’ snake_case names (grant_type,client_id,expires_in). - A managed vault’s secrets and their metadata use snake_case:
max_versions,cas_required,delete_version_after,custom_metadata,created_time. The rest of the Secrets Store, such as grants and emergency access, is camelCase.
Rate limits
Section titled “Rate limits”The admin APIs apply no rate limit today: no call is refused for coming too often. That isn’t a promise of unlimited throughput, and a rate limit is planned. Write scripts so they won’t break when it arrives:
- Back off on
429and503. Wait the number of seconds inRetry-Afterwhen the answer carries one, and otherwise wait a second, then two, then four, before trying again. - Keep to a few calls at once. Page through a large list one page at a time rather than all pages in parallel.
- Reuse one session. Signing in again doesn’t help; see Sessions in scripts.
The OAuth 2.0 endpoints answer 503 with temporarily_unavailable when they can’t take a request; retry it later.
Limits and defaults
Section titled “Limits and defaults”| What | Default | Range or cap |
|---|---|---|
| Rate limit on the admin APIs | None | Planned |
| A list’s page size | 20 | 1 to 100 |
| A request body | 10 MiB | |
Sessions per user (sessionQuota) | 10 | 1 to 20 |
A session’s lifetime (maxSessionMinutes) | 120 minutes | 1 to 43,200 |
A session’s idle window (maxIdleMinutes) | 30 minutes | 1 to 1,440 |
Every limit a realm has is in Limits.
Troubleshooting
Section titled “Troubleshooting”- A script’s calls start answering
401partway through a run. Its session ended: it reachedmaxSessionMinutes, sat idle pastmaxIdleMinutes, or a later sign-in by the same account pushed it pastsessionQuota. Sign in once per run, and sign in again on401. - The dashboard signs you out while a script runs. The script signs in as you, and each sign-in past your quota ends your oldest session. Give the script its own account.
- Every write answers
415. The body isn’t sent as JSON: add-H "Content-Type: application/json". - Writes answer
403from a browser page and work fromcurl. The page’s origin isn’t allowed to write with the session cookie: see Allowed origins.
Errors
Section titled “Errors”An error answers with the status that fits and a body of code, message and detail:
{ "code": "REVISION_CONFLICT", "message": "<what went wrong>", "detail": "<more, when there is more>" }code is stable and is what a script should test; message is for a person and may change. Two kinds of answer
don’t use this shape:
- A precondition the realm can’t apply (an
If-Matchthat doesn’t read, a weak tag,If-Match: *on a missing object,If-None-Match: *on one that exists) answers400or412as an RFC 9457 problem:application/problem+json, withtype,title,statusanddetail. - A refusal at the door (a write whose body isn’t JSON, or a write carrying the session cookie from a web origin that isn’t allowed) answers in plain text.
| Status | Codes | What it means |
|---|---|---|
400 | INVALID_REQUEST, MISSING_FIELD, SCHEMA_VALIDATION_FAILED, POLICY_VIOLATION | The request doesn’t read, or the object doesn’t fit its type’s schema or rules. detail names the field |
401 | UNAUTHORIZED | No session, or one that has ended. Sign in again |
401 | INVALID_CREDENTIALS | A sign-in step was answered wrongly |
403 | FORBIDDEN | Your session is valid, and your rights don’t cover this object; or the product isn’t turned on for the realm |
404 | NOT_FOUND | No such object, type or realm, or not one your session can see |
405 | METHOD_NOT_ALLOWED | The address exists and doesn’t take this method |
408 | LOGIN_TIMEOUT | A sign-in was left too long between steps. Start again |
409 | ALREADY_EXISTS, SINGLETON_EXISTS | An object with that id already exists, or a setting already has its one object |
409 | DISABLED | The feature is off for the realm until a realm administrator turns it on, such as the Secrets Store |
412 | REVISION_CONFLICT | The object changed since you read it. Read it again and retry |
413 | PAYLOAD_TOO_LARGE | The request body is over 10 MiB |
415 | A write whose body isn’t JSON | |
421 | MISDIRECTED_REQUEST | The request reached a host other than the one its connection was opened to. Open a connection to that host |
428 | PRECONDITION_REQUIRED | This type needs If-Match on every write |
429 | Not sent today. Once rate limits arrive: too many requests; wait Retry-After seconds and retry | |
502, 503, 504 | UPSTREAM_FAILED, UNAVAILABLE, UPSTREAM_TIMEOUT | A part of the realm didn’t answer in time. The same request may succeed later |
500 | INTERNAL_ERROR | Ours, not yours |