Bearer tokens in the Authorization header.
Bearer Token
Include the access token on every protected request:Service Keys and actingUserId
Server-to-server requests can authenticate with a service key instead of a user’s access token. A service key has no user of its own; to act as a user, it names that user in actingUserId: in the query string on a GET or DELETE, in the body on a POST, PATCH or PUT, like every other field (see Where each input goes). The request then runs with that user’s permissions and is recorded as theirs.
- A user token always acts as its own user. Sending
actingUserIdwith a user token, or with no credentials, returns400 <resource>/acting-user-not-allowed, even when it names the token’s own user. An endpoint that requires sign-in may answer a request with no credentials with401first. Endpoints that always act as the app (below) answer400 <resource>/unsupported-paraminstead, to every caller. - A service key can only name a user who exists in the project. On every endpoint that accepts
actingUserId, an id that isn’t a user in this project returns404 <resource>/user-not-found(No user with this actingUserId exists in this project.) before the request runs. - An endpoint that needs an acting user returns
400 <resource>/missing-user-id(A service key must send actingUserId: the user this request acts as.) to a service key that sends none. Among them are deleting a space, every workspace endpoint except reading a single workspace, and Update User. On Update User, a key must name the user in the path (403 user/forbiddenotherwise), and the request behaves exactly as that user’s own token. - On reads shaped by who is looking (entities, comments and their reaction lists; events and RSVP lists; spaces, their member and team lists, rules and breadcrumb; a single workspace; user profiles and suggestions, follower, following and connection lists and their counts, a user’s comment history, user search, content search and Ask),
actingUserIdis optional: with it, the response is exactly what that user’s own token would get; without it, exactly the anonymous view. Listing reputation grants needs credentials, so a key naming nobody gets what a signed-in user in no conversation gets. - Editing, deleting or publishing an entity, editing or deleting a comment, and deleting a file act as the record’s owner: for a record with an author, a key must name the author (
400 <resource>/missing-user-idwithout it); a record with no author belongs to the app, and only a key naming nobody may change it. A draft with no author is answered as not found (404). - Creating an entity or uploading a file without
actingUserIdmakes an app-owned record. A service key may always create an entity without an author; for other callers (no credentials on Create Entity, any client withcreateIfNotFound) the project’s Who can create entities without an author setting decides, and a refused caller gets403 entity/authorless-creation-not-allowed. A draft needs an owner (400 entity/draft-requires-userotherwise). A service key may backdate entities and comments (createdAt/updatedAt), also when acting as a user; a date more than five minutes in the future returns400 <resource>/invalid-body(createdAt can't be in the future.orupdatedAt can't be in the future.). - Endpoints that always act as the app (deleting a user, sending push notifications, minting reputation, incrementing an entity’s view count, creating or dropping custom tables and columns) refuse
actingUserIdwith400 <resource>/unsupported-param. - Endpoints where no user’s view matters (checking a username, link metadata, a file’s info) ignore
actingUserId, like any other field they don’t use. - Endpoints where the person must prove it’s them (changing or setting a password, account deletion, OAuth link and identities, push device registration) refuse a service key with
403 <resource>/user-token-required. userIdonly names a user the request is about — a target, or a filter such as the author filter on Fetch Entities. Don’t send the acting user asuserId: most endpoints that take an acting user refuse auserIdfield with400 <resource>/unsupported-paramand"param": "userId"(workspace endpoints with400 workspace/invalid-bodyorworkspace/invalid-query). A service key is told to sendactingUserIdinstead; a user token, or a request with no credentials, is told that its token already acts as its user. Each endpoint’s page lists the error.
<resource> is the endpoint’s own code prefix, for example comment or chat. See Acting as a user.
Obtaining Tokens
Tokens are issued by the auth endpoints. Depending on your auth setup:
All of these return the same token structure:
202 { "success": true, "emailVerificationRequired": true } with no tokens instead, and an account with a password and an unconfirmed email is refused tokens by every method — sign-in and token refresh with 403 auth/email-not-verified, OAuth with error=account_email_not_confirmed. See Require Email Verification.
Refreshing Tokens
When an access token expires, use the refresh token to obtain a new access token:accessToken and a rotated refreshToken. Always store and use the latest refresh token — reusing a revoked one will invalidate the entire session. Each rotated refresh token is valid for another 30 days, so active users stay signed in indefinitely. Only if a refresh token goes unused for 30 days will it expire and require the user to sign in again.
See Request New Access Token for full details.
SDK Token Management
If you are using the Sublay SDK (@sublay/react-js, @sublay/react-native, etc.), you do not need to manage tokens manually. The SDK stores tokens, attaches them to every request, and automatically refreshes them before they expire.
Token management is only relevant when calling the REST API directly — for example, from a server-side environment using the Node SDK or a custom HTTP client.
Unauthenticated Requests
Some endpoints are publicly accessible without a token (e.g., fetching public entity data). These endpoints do not require anAuthorization header.
On endpoints that require auth, a missing header and a bad one are answered differently:
Public endpoints ignore an unusable token
Endpoints that treat the viewer as optional do not reject a token they cannot verify — they answer200 and simply treat the caller as anonymous. A request
carrying an expired token therefore succeeds, but comes back without any
viewer-specific data: the caller’s own reactions, saved state, and block
filtering are all absent, with nothing in the response to signal it.
If you are integrating directly, refresh proactively rather than waiting for an
error on these routes. The official SDKs do this for you.
