Authentication
The three credentials the Pagebread API accepts, for workspace members, applicants and portal members, and how each is obtained.
The API has three kinds of caller, and each has its own credential. They are kept strictly apart: a member session never opens a console route, and a console token never opens the member portal.
| Caller | Credential | Refused with |
|---|---|---|
| A person in your workspace | Authorization: Bearer <access token> | 401 UNAUTHORIZED |
| An applicant filling in a form | X-Applicant-Secret: <secret> on their own draft | 404 NOT_FOUND |
| A member in the member portal | The pagebread_member_session cookie | 401 MEMBER_UNAUTHENTICATED |
Console routes: bearer access tokens
Console routes take the access token of a signed-in Pagebread account in the Authorization header. This is the token Pagebread's sign-in (Supabase Auth) issues when someone signs in to the console. An API key is not accepted here: API keys are for the public API at /v1.
curl "$PAGEBREAD_API/api/v2/policies?page=1&per_page=20" \
-H "Authorization: Bearer $TOKEN"const res = await fetch(`${API}/api/v2/policies?page=1&per_page=20`, {
headers: { Authorization: `Bearer ${token}` },
})
const { data, meta } = await res.json()On every request the server:
- verifies the token with the identity provider (an expired, revoked or unverifiable token is
401 UNAUTHORIZED, with the same body whatever the cause; when the identity provider can't be reached, times out or is rate-limiting, the answer is503 AUTH_UNAVAILABLEwithRetry-After, and the token is not treated as invalid); - finds the workspace this account is a member of, and its role there;
- checks the role has the permission the route needs.
Nothing in the request can choose the workspace or the role. A record in another workspace, a record that doesn't exist and an action your role doesn't allow all answer 404 NOT_FOUND. See Security overview.
Warning
An access token acts as the person it belongs to, with their role. Treat it like a password, and expect it to expire: refresh it the way the sign-in library does rather than storing it.
Other refusals you may meet on console routes:
| Code | Status | Meaning |
|---|---|---|
PROFILE_INCOMPLETE | 403 | The workspace profile must be completed first. |
CREATOR_ACCOUNT | 403 | The account is a marketplace creator account, which has no workspace. |
WORKSPACE_SUSPENDED | 403 | The workspace is read-only; reads still work. |
READ_ONLY_CONSOLE | 503 | Pagebread is in maintenance; reads still work. |
AUTH_UNAVAILABLE | 503 | The sign-in couldn't be checked right now. Retry after Retry-After. |
ORGANIZATION_UNAVAILABLE | 503 | Your workspace, or its profile, couldn't be loaded right now. This includes GET /api/v2/organizations/me, the onboarding routes and accepting an invitation. Retry after Retry-After. |
Deleting an account (DELETE /api/v2/account) also needs a token from a sign-in in the last 5 minutes, or it answers 403 REAUTHENTICATION_REQUIRED.
Applicant routes: the draft secret
Someone applying through a public link has no account. Instead, the draft they start is protected by a secret.
Start a draft
POST /api/v2/submissions with the flow's id. The response returns the secret once, in meta.applicant_secret. Only a hash of it is stored, so it can't be shown again.
Present it on every change
Send the secret in the X-Applicant-Secret header on PATCH /api/v2/submissions/:id, POST /api/v2/submissions/:id/answers and POST /api/v2/submissions/:id/documents.
Submit
PATCH the draft with "status": "submitted". After that the applicant can no longer change it, except to answer an open request for changes.
# Start a draft
curl -X POST "$PAGEBREAD_API/api/v2/submissions" \
-H "Content-Type: application/json" \
-d '{"flow_id": "<flow id>"}'
# → { "data": { "id": "<submission id>", … }, "meta": { "applicant_secret": "<secret>" } }
# Save answers with the secret
curl -X POST "$PAGEBREAD_API/api/v2/submissions/<submission id>/answers" \
-H "Content-Type: application/json" \
-H "X-Applicant-Secret: <secret>" \
-d '{"answers": [{"field_key": "full_name", "value": "Asha Rao"}]}'const created = await fetch(`${API}/api/v2/submissions`, {
method: 'POST',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ flow_id: flowId }),
}).then(r => r.json())
const id = created.data.id
const secret = created.meta.applicant_secret
await fetch(`${API}/api/v2/submissions/${id}/answers`, {
method: 'POST',
headers: { 'Content-Type': 'application/json', 'X-Applicant-Secret': secret },
body: JSON.stringify({ answers: [{ field_key: 'full_name', value: 'Asha Rao' }] }),
})A missing or wrong secret answers exactly as if the submission didn't exist: 404 NOT_FOUND. A submission that has left the applicant's hands answers 409 SUBMISSION_LOCKED. When the organization can't take new applications, starting a draft answers 409 FORM_PAUSED.
Member portal: sign-in links and sessions
Members sign in to the portal with a one-time link sent by email.
Request a link
POST /api/v2/public/members/magic-links with {"email": "…"}. The answer is always 202, whether or not the address is on a roster, so it reveals nothing. If it is, each organization whose roster has the address sends its own link.
Redeem it
The link opens the member portal, which sends its token to POST /api/v2/public/members/sessions with {"token": "…"}. A valid link starts a session and sets the pagebread_member_session cookie: HTTP-only, SameSite=Lax, for 14 days. Links last 30 minutes and work once. An expired, used or unknown link always answers the same 400 INVALID_MAGIC_LINK.
Use the session
Routes under /api/v2/public/members/ read the member from the cookie, for example GET /api/v2/public/members/me. DELETE /api/v2/public/members/sessions signs out.
curl -X POST "$PAGEBREAD_API/api/v2/public/members/sessions" \
-H "Content-Type: application/json" \
-c cookies.txt \
-d '{"token": "<token from the link>"}'
curl "$PAGEBREAD_API/api/v2/public/members/me" -b cookies.txtawait fetch(`${API}/api/v2/public/members/sessions`, {
method: 'POST',
credentials: 'include',
headers: { 'Content-Type': 'application/json' },
body: JSON.stringify({ token }),
})
const me = await fetch(`${API}/api/v2/public/members/me`, { credentials: 'include' })Important
A change sent with the member cookie from a page whose origin Pagebread doesn't allow is refused with 403 ORIGIN_NOT_ALLOWED. Browsers can only use the member session from Pagebread's own pages.
Sign-in requests are rate limited per address and per client; see Rate limits.