Skip to main content
Most Sublay API endpoints require an authenticated user. Authentication uses short-lived JWT access tokens passed as Bearer tokens in the Authorization header.

Bearer Token

Include the access token on every protected request:
Access tokens expire after 30 minutes.

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 actingUserId with a user token, or with no credentials, returns 400 <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 with 401 first. Endpoints that always act as the app (below) answer 400 <resource>/unsupported-param instead, 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 returns 404 <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/forbidden otherwise), 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), actingUserId is 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-id without 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 actingUserId makes 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 with createIfNotFound) the project’s Who can create entities without an author setting decides, and a refused caller gets 403 entity/authorless-creation-not-allowed. A draft needs an owner (400 entity/draft-requires-user otherwise). 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 returns 400 <resource>/invalid-body (createdAt can't be in the future. or updatedAt 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 actingUserId with 400 <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.
  • userId only 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 as userId: most endpoints that take an acting user refuse a userId field with 400 <resource>/unsupported-param and "param": "userId" (workspace endpoints with 400 workspace/invalid-body or workspace/invalid-query). A service key is told to send actingUserId instead; 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:
When the project requires email verification before sign-in (Dashboard → Settings → SDK), sign-up returns 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:
The response includes a new 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 an Authorization header. On endpoints that require auth, a missing header and a bad one are answered differently:
An expired token returns 403, not 401. If you are calling the REST API directly, this is the case to build your refresh logic around — a client that only refreshes on 401 will never refresh, and will start failing once its first access token passes its 30-minute TTL.Both responses are text/plain with no JSON body and no code field. Every other 401/403 the API returns does carry a code (auth/elevated-auth-required, project/plan-required, user/suspended, …). Those describe a decision no token refresh can change, so the presence of a code is a reliable way to tell “retry after refreshing” apart from “stop and surface this to the user”.

Public endpoints ignore an unusable token

Endpoints that treat the viewer as optional do not reject a token they cannot verify — they answer 200 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.