Create an API key
const url = 'https://app.caprid.com/v1/account/api-keys';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"label":"staging-ci","expires_in":7776000,"namespaces":["acme-staging"]}'};
try { const response = await fetch(url, options); const data = await response.json(); console.log(data);} catch (error) { console.error(error);}curl --request POST \ --url https://app.caprid.com/v1/account/api-keys \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "label": "staging-ci", "expires_in": 7776000, "namespaces": [ "acme-staging" ] }'POST /v1/organizations/{id}/api-keys for the API key’s Organization.
Authorizations
Section titled “Authorizations”Request Body
Section titled “Request Body”object
A name to tell the key apart from others. Defaults to api.
Seconds until the key stops working. 0 means never.
Limits the key to these Namespaces, each a live Namespace of the Organization. Leave it out for a key that reaches the whole Organization. A limited key manages only the Signing keys, Client tokens and settings of its Namespaces, and can’t create API keys. You can’t change the limit later.
Example
{ "label": "staging-ci", "expires_in": 7776000, "namespaces": [ "acme-staging" ]}Responses
Section titled “Responses”The new API key, with its secret.
object
Identifies the key for revoking it. Not a secret.
The first 6 characters of the secret after sb_, so you can tell keys apart.
Absent for a key that never expires.
Absent for a key that has never been used.
The Namespaces the key is limited to, by name. Absent for a key
with no limit. A deleted Namespace drops out, so a key whose
Namespaces have all been deleted has [] here and can do nothing.
The API key itself. Shown only in this response.
Example
{ "id": "3f9a1c07be42", "namespaces": [ "acme-staging" ], "secret": "sb_R2x0Z9kQ7mVt3xLp8wNc1bYh5sDf2gJr6uEa0zWiTq4"}Sent with a session, which may belong to several Organizations. Use the route the message names instead. This route also returns 400 for anything that route would refuse with 400.
object
Example
{ "error": "this route is for API keys; use /v1/organizations/{id}/api-keys"}No valid credential. Missing, expired and revoked credentials all get the same response, and so does an API key whose trial has lapsed. An Agent token from before a claim gets a 401 too, once the claim has made the trial a person’s, with a message saying to get a new token.
object
Example
{ "error": "the requested grants exceed the key's scope"}Headers
Section titled “Headers”Example
Bearer realm="switchboard"Sent with an API key limited to some Namespaces, to a Namespace outside its limit, or to a route that acts on the Organization as a whole. A limited key can never create API keys.
object
Example
{ "error": "this API key is limited to the Namespaces acme-staging, and acme isn't one of them"}