API
API overview
The base URL, authentication, error format and limits that apply to every PerkHost API route.
Base URL and format
Every route lives under https://api.perkhost.com/api/v1. Requests and responses are JSON, and a request with a body needs the header Content-Type: application/json. Request bodies are strict: a field the route does not define is rejected.
curl -sS https://api.perkhost.com/api/v1/healthGET /health is public. It answers { "status": "ok", "db": "up", "version": "..." }, or 503 with status: "degraded" and db: "down" when the database cannot be reached.
Authentication
- Send
Authorization: Bearer <token>on every route that is not marked public in the reference. - A session token comes from
POST /auth/loginand works on every signed-in route. See "Accounts and sessions". - A personal API token (
phk_...) works only on routes marked "API token" in the reference, only if it carries the scope the route needs, and only for its own workspace. See "API tokens". - A missing, invalid or expired token gets 401.
Workspaces and access
Workspace routes are nested under /workspaces/{workspaceId}. The API looks up your membership on every request. If you are not a member, the answer is 404, the same as for a workspace that does not exist. If you are a member without the needed role, the answer is 403. See "Workspaces, roles and members".
Errors
An error answers with the status code and a JSON body with a message you can show to a person. Some errors add a machine-readable code.
{
"message": "Validation failed",
"issues": [{ "path": "email", "message": "Invalid email address" }]
}| Status | Meaning |
|---|---|
| 400 | The body, query or a path parameter is invalid. issues lists each field. |
| 401 | Missing, invalid, revoked or expired credentials, or an API token on a route that does not accept one. |
| 402 | The workspace plan does not allow this. code is plan_required, with the feature and planId. |
| 403 | Your role is not allowed this action, an API token lacks the scope the route needs, or you are past the two-factor deadline without a second factor (code: mfa_enrolment_required). |
| 404 | Not found, or not visible to you. |
| 409 | The request conflicts with the current state, for example a person who is already a member of the workspace, or billing_not_configured. |
| 429 | Too many requests. Wait for the number of seconds in the Retry-After header. |
| 503 | A rate-limited write route is temporarily unavailable because the shared rate-limit store is down. Wait for the Retry-After header and retry. |
Rate limits
Sign-in, registration, password reset, token refresh, two-factor and API token creation are rate limited, as are several write routes. The exact limits can change, so handle 429 by waiting for Retry-After rather than counting requests.
Routes that are not documented here
The reference covers the routes people and their scripts call. Routes for PerkHost operators and for the servers PerkHost runs, and the signed Stripe webhook, are not part of the public API and are not listed.