Mint a Client token
const url = 'https://app.caprid.com/v1/tokens';const options = { method: 'POST', headers: {Authorization: 'Bearer <token>', 'Content-Type': 'application/json'}, body: '{"path":"room/42","subscribe":""}'};
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/tokens \ --header 'Authorization: Bearer <token>' \ --header 'Content-Type: application/json' \ --data '{ "path": "room/42", "subscribe": "" }'POST /v1/namespaces/{namespace}/tokens for the API key’s only Namespace.
Authorizations
Section titled “Authorizations”Request Body
Section titled “Request Body”object
The kid of the Signing key to sign with. You can leave it out when the Namespace has exactly one.
Where the token is rooted, relative to the Namespace. The
token’s root claim is <namespace>/<path>.
Seconds until the token expires. 0 means never.
Examples
Watch one room for an hour
{ "path": "room/42", "subscribe": ""}Publish your own broadcast and watch everyone else's
{ "path": "room/42", "publish": "alice", "subscribe": "", "expires_in": 14400}Responses
Section titled “Responses”The signed token and what it grants.
object
A JWT. Give it to the Client, which passes it to the relay as ?jwt=.
A Client token’s payload. root is absolute and starts with your
Namespace. put (publish) and get (subscribe) are prefixes relative
to root.
object
When the token expires. Absent for a token that never expires.
When the token was issued.
Example
{ "claims": { "root": "acme/room/42", "get": [ "" ] }}Sent with a session, or with an API key that doesn’t reach exactly one Namespace. Use the route the message names instead. This route also returns 400 for anything that route would refuse with 400.
object
Example
{ "error": "this API key reaches 2 Namespaces, so this route can't tell which one you mean; use /v1/namespaces/{namespace}/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"}No such thing, or not yours. Another customer’s Organization or Namespace is a 404 too, so nobody can tell which ones exist.
object
Example
{ "error": "the requested grants exceed the key's scope"}