Workspaces
API tokens
Create a personal API token for one workspace with the scopes it needs, use it on the routes that accept it, and revoke it.
A personal API token lets a script or CI job call the API without your password. A token belongs to you and to one workspace. It starts with phk_.
Dashboard or API
Create a token
- Sign in with
POST /auth/loginand keep thetokenit returns. See "Accounts and sessions". - Call
POST /workspaces/{workspaceId}/api-tokenswith that session token, anameof up to 100 characters, thescopesthe token needs and optionallyexpiresInDays. - Copy the
tokenfrom the response now. It is shown once and cannot be read again.
curl -sS -X POST https://api.perkhost.com/api/v1/workspaces/$WORKSPACE_ID/api-tokens \
-H "Authorization: Bearer $SESSION_TOKEN" \
-H 'Content-Type: application/json' \
-d '{"name":"ci","scopes":["members:read"],"expiresInDays":30}'scopesis required: at least one ofmembers:readandsubscription:read, with no repeats. There is no default, so a token never gets more access than you asked for.- Every token expires.
expiresInDaysdefaults to 90 and may be 1 to 365. To renew, create a new token. - You may hold up to 25 active tokens per workspace. Creating one beyond that gets 409.
- Creating tokens is rate limited per user, and a limited request gets 429.
- PerkHost stores only a hash of the token. Lists show the first 12 characters as the
prefix.
Use a token
Send it as Authorization: Bearer phk_.... A token works only on routes that accept tokens, and only if it carries the scope the route needs. On top of its scope, it acts with the role its creator holds in that workspace at the moment of the request. Today there are two scopes, one per route:
| Scope | Route | Roles that may call it |
|---|---|---|
| members:read | GET /workspaces/{workspaceId}/members | owner, admin, developer |
| subscription:read | GET /workspaces/{workspaceId}/subscription | owner, admin, billing |
curl -sS https://api.perkhost.com/api/v1/workspaces/$WORKSPACE_ID/subscription \
-H "Authorization: Bearer $PERKHOST_TOKEN"A token without the scope gets 403 with the message "API token lacks the required scope" and the scope. On any other route a token gets 401 with the message "API tokens are not accepted on this route". A token used on another workspace gets 404. Managing tokens is session-only on purpose, so a leaked token cannot create more tokens or hide itself.
List and revoke
GET /workspaces/{workspaceId}/api-tokenslists your active tokens, newest first, withid,name,prefix,scopes,createdAt,lastUsedAtandexpiresAt.DELETE /workspaces/{workspaceId}/api-tokens/{tokenId}revokes one and answers 204, also when it was already revoked.
Tokens of other members
Owners and admins can list every active token in the workspace and revoke them, so a departing or compromised member's tokens can be cut without removing the member. GET /workspaces/{workspaceId}/member-api-tokens pages through the tokens, newest first, and each item names its owner. It never returns a token or its hash. DELETE /workspaces/{workspaceId}/member-api-tokens/{tokenId} revokes one; only an owner can revoke a token held by an owner, and an admin gets 403 for one. Both are session-only: a token gets 401, and a developer, billing member or client gets 403.
When a token stops working
- It was revoked, by you or by an owner or admin, or it expired.
- Its creator was removed from the workspace.
- Its creator reset their password, or turned a two-factor factor on or off.
- A refresh token of its creator was used again after it had been rotated. Tokens created in that session are revoked, and so are all the creator's tokens unless the reuse came within 5 seconds of the rotation.
- Its creator passed the two-factor enrolment deadline without a second factor. The token then gets 403.
The CLI signs in with one of these tokens. See "The perkhost command".