Skip to main content
The users module provides server-side access to user profiles, social graph data (follows and connections), and username availability. All operations use your project API key and do not require a user access token. Reads that depend on who is looking (profiles, suggestions, follower, following and connection lists and counts, comment history) take an optional actingUserId to read as that user; without it they return the anonymous view. updateUser acts as the user being updated, so it requires actingUserId set to that user; deleteUser acts as your app and takes no actingUserId.

fetchUserById

Fetches a user profile by their internal Sublay user ID.
string
required
The Sublay user ID.
string
Read as this user: the result is exactly what their own access token would get, so a profile whose owner blocked them comes back as 404. Omit for the anonymous view.
UserIncludeParam
Associations to populate, as a single value or an array. The only value is "files", which populates avatarFile and bannerFile.
Returns — Promise<User>

fetchUserByForeignId

Fetches a user profile by your application’s own user identifier. It only reads: a user that doesn’t exist throws a 404. To create the user when missing, use fetchOrCreateUserByForeignId.
string
required
Your application’s user identifier, matched exactly as sent. A blank or whitespace-only one is refused with 400 user/invalid-query.
string
Read as this user: the result is exactly what their own access token would get, so a profile whose owner blocked them comes back as 404. Omit for the anonymous view.
UserIncludeParam
Associations to populate, as a single value or an array. The only value is "files", which populates avatarFile and bannerFile.
Returns — Promise<User>

fetchOrCreateUserByForeignId

Returns the user with your application’s identifier, or creates them with the given profile when there is none. An existing user comes back unchanged: the profile fields are used only to create. The request sends everything in the body, so the profile never appears in a URL. Props type: FetchOrCreateUserByForeignIdProps. See POST /users/by-foreign-id.
string
required
Your application’s user identifier, kept exactly as sent. A blank or whitespace-only one is refused with 400 user/invalid-body.
string | null
Display name, or null for none — used only when creating a new user.
string
Username — used only when creating a new user. 3 to 30 characters after trimming, only letters, numbers, underscores (_) and hyphens (-); anything else throws a 400 (user/invalid-body). A username another user already holds throws a 409 (user/username-taken, with param: "username").
string | null
Avatar URL, or null for none — used only when creating a new user.
string | null
Bio text, or null for none — used only when creating a new user.
object
Public metadata, a JSON object — used only when creating a new user. The whole request body can be at most 100 KB.
object
Secure metadata, a JSON object, used only when creating a new user. No API response returns it to any user. Users can also write their own, so don’t treat it as trusted.
UserIncludeParam
Associations to populate, as a single value or an array. The only value is "files", which populates avatarFile and bannerFile.
string
Read as this user: a user who has blocked them comes back as 404, and nothing is created. It never changes who creates: a user this call creates is always created by the app.
Returns — Promise<FetchOrCreateUserByForeignIdResult>: { user: User; created: boolean }. created is true when this call created the user (HTTP 201) and false when the user already existed (HTTP 200, also when another call created them concurrently).

fetchUserByUsername

Fetches a user profile by their username.
string
required
The user’s unique username.
string
Read as this user: the result is exactly what their own access token would get, so a profile whose owner blocked them comes back as 404. Omit for the anonymous view.
UserIncludeParam
Associations to populate, as a single value or an array. The only value is "files", which populates avatarFile and bannerFile.
Returns — Promise<User>

updateUser

Updates a user’s profile fields. The update acts as that user: actingUserId must be the same user as userId, and the request behaves exactly as their own access token would (403 user/forbidden if the two differ).
string
required
The Sublay user ID to update.
string
required
The user the request acts as. Must be the same user as userId.
string | null
New display name. null or an empty string clears it.
string
New username. Must be available: a username another user already holds throws a 409 (user/username-taken, with param: "username").
string | null
New bio text. null or an empty string clears it.
string | null
New avatar URL, stored as given; null clears it. Separate from avatarFile, which uploads an image.
object
Updated public metadata. Replaces the stored object; send the whole object, including keys you aren’t changing.
object
Updated secure metadata. No API response returns it to any user. Users can also write their own, so don’t treat it as trusted. Replaces the stored object, like metadata.
string | Date
The user’s birthdate: a Date, or a full UTC timestamp string such as "1990-05-17T00:00:00.000Z". A date alone ("1990-05-17") or a time with an offset is refused with 400 user/invalid-body and param: "birthdate".
object
Geographic location { latitude: number; longitude: number }.
{ file: Uint8Array | Blob; filename?: string; mimeType?: string; options: ImageOptions }
A new avatar image, replacing the current one (up to 50 MB). Raw bytes carry no type, so pass mimeType with a Uint8Array (image/jpeg, image/png or image/webp; without it the file goes as application/octet-stream and is refused with 400 user/unsupported-file-type); a Blob keeps its own type. options says how to process the image and must include mode (see Upload Image). With an image, the request is sent as multipart/form-data. A field set to null can’t travel with an image: the call throws before sending anything, so clear it in a separate call without one.
{ file: Uint8Array | Blob; filename?: string; mimeType?: string; options: ImageOptions }
A new banner image, replacing the current one; same shape as avatarFile.
string[]
Files to remove: the user’s avatarFileId and/or bannerFileId, nothing else. Removing one clears that image. Works alone or with uploads. Any other id throws a 400 (user/invalid-remove-file-ids, with invalidIds).
Returns — Promise<AuthUser> — the updated user as they see themselves (see AuthUser).

deleteUser

Permanently deletes a user and cascades cleanup across all of their related data — reactions, files, follows, connections, notifications, collections and the user’s own report filings are removed (a report others also filed stays open, one reporter fewer), and their drafts are deleted with everything attached to them. Their published entities and comments stay, with no author and stripped of everything they wrote, metadata included (and an entity’s keywords and location); their comments are marked deleted. Their chat messages stay in their conversations as deleted, the same as if the user had deleted each one: content, GIF, mentions and metadata cleared, and userDeletedAt set. Mentions of the user in other entities, comments and chat messages keep their text, but their id and foreignId become null. This mirrors the full-cascade delete performed from the dashboard. Open reports on the user’s content are closed (status: "auto-closed", actionTaken: "Its author's account was deleted.") and kept as history.
This is a hard, irreversible delete — the user and their related data cannot be recovered.
string
required
The Sublay user ID to delete.
Returns — Promise<void>

fetchUserSuggestions

Returns users whose name or username matches a partial query string. Useful for mention autocomplete on the server.
string
required
Partial name or username to search for.
string
Read as this user: the result is exactly what their own access token would get, so users block-edged with them are left out. Omit for the anonymous view.
Returns — Promise<{ data: User[] }>

checkUsernameAvailability

Checks whether a username is available for registration.
string
required
The username to check.
Returns — Promise<{ available: boolean }>

fetchCommentsByUserId

Returns a user’s comments — top-level comments and replies alike, across entities — cursor-paginated. See Fetch Comments by User.
Pass actingUserId to read the history as that user: their own moderator-removed comments are included in full, the block rules and blockedFilter apply from their perspective (comments on an entity whose author blocked them are left out, except their own), the isAuthorBlocked / isUnavailable flags are set, userReaction is populated, and the moderation details are what that user may see. Without it the read is anonymous: deleted and moderator-removed comments are left out, no block rule applies, isAuthorBlocked and isUnavailable are always false, userReaction isn’t populated, and no moderation details are included.
string
required
The Sublay user ID whose comments to fetch.
string
The user to read the history as: the result is exactly what their own access token would get. Omit for the anonymous view.
string
Only comments on this entity.
string | "none"
Only comments on entities from this source, or "none" for comments on entities with no source. Left out: any source.
"exclude" | "include-outbound-blocked"
How comments by users actingUserId is block-edged with are treated: "exclude" (default) leaves them out; "include-outbound-blocked" re-includes comments by users they blocked, marked isAuthorBlocked: true. No effect without actingUserId.
number
Comments per page. Server default 10, max 100.
string | null
pagination.nextCursor from the previous response, passed as returned. Omit it, or pass null, for the first page. Send the same sort as the request that returned it.
"createdAt" | "top" | "controversial"
Server default "createdAt". "top" ranks by the raw count of sortByReaction.
"asc" | "desc"
Applies to "createdAt" and "top"; not accepted with "controversial", which ranks one way only. Server default "desc".
ReactionType
With sortBy: "top" only. Server default "upvote".
CommentIncludeParam
Related data to populate: "user", "entity", "space", "parent", "grants", "files" (the comment’s images and files; requires the files-images bundle).
Returns — Promise<CursorPaginatedResponse<Comment>> — { data, pagination: { nextCursor, hasMore } }

fetchFollowersByUserId

Returns a paginated list of the specified user’s followers.
string
required
The Sublay user ID.
string
Read as this user: the result is exactly what their own access token would get, so users block-edged with them are left out. Omit for the anonymous view.
number
Page number (1-indexed). Defaults to 1.
number
Results per page: a whole number from 1 to 100. Defaults to 20. A larger value is rejected with 400 follow/invalid-query, never lowered to 100.
string
Optional search term. Filters the list to users whose username or name contains this text (case-insensitive). When omitted, no filtering is applied.
string
Restricts which field query matches against — username or name. When omitted, query matches either field.
Returns — Promise<PaginatedResponse<FollowRow>> — each FollowRow is { id, user, createdAt }, where user is the follower.

fetchFollowersCountByUserId

Returns the total number of followers for a user.
string
required
The Sublay user ID.
string
Read as this user: the result is exactly what their own access token would get, so users block-edged with them are left out. Omit for the anonymous view.
Returns — Promise<{ count: number }>

fetchFollowingByUserId

Returns a paginated list of users that the specified user is following.
string
required
The Sublay user ID.
string
Read as this user: the result is exactly what their own access token would get, so users block-edged with them are left out. Omit for the anonymous view.
number
Page number (1-indexed). Defaults to 1.
number
Results per page: a whole number from 1 to 100. Defaults to 20. A larger value is rejected with 400 follow/invalid-query, never lowered to 100.
string
Optional search term. Filters the list to users whose username or name contains this text (case-insensitive). When omitted, no filtering is applied.
string
Restricts which field query matches against — username or name. When omitted, query matches either field.
Returns — Promise<PaginatedResponse<FollowRow>> — each FollowRow is { id, user, createdAt }, where user is the followed user.

fetchFollowingCountByUserId

Returns the number of users the specified user is following.
string
required
The Sublay user ID.
string
Read as this user: the result is exactly what their own access token would get, so users block-edged with them are left out. Omit for the anonymous view.
Returns — Promise<{ count: number }>

fetchConnectionsByUserId

Returns a paginated list of a user’s accepted connections.
string
required
The Sublay user ID.
string
Read as this user: the result is exactly what their own access token would get, so users block-edged with them are left out. Omit for the anonymous view.
number
Page number (1-indexed). Defaults to 1.
number
Results per page: a whole number from 1 to 100. Defaults to 20. A larger value is rejected with 400 connection/invalid-query, never lowered to 100.
string
Optional search term. Filters the list to connections whose other user’s username or name contains this text (case-insensitive). When omitted, no filtering is applied.
string
Restricts which field query matches against — username or name. When omitted, query matches either field.
Returns — Promise<PaginatedResponse<AcceptedConnectionRow>> — each AcceptedConnectionRow is { id, user, status, createdAt, respondedAt }, where user is the specified user’s connection.

fetchConnectionsCountByUserId

Returns the number of accepted connections for a user.
string
required
The Sublay user ID.
string
Read as this user: the result is exactly what their own access token would get, so users block-edged with them are left out. Omit for the anonymous view.
Returns — Promise<{ count: number }>

Acting on a user’s follows and connections

The functions above are read-only queries about a target user. The functions below perform an action on behalf of one user toward another, so they take both:
  • userId — the target of the action (the user being followed, connected with, etc.), taken from the request path.
  • actingUserId — the user the service key acts as (the follower, the requester, the user whose perspective a status is from).
Listing and managing the acting user’s own follow/connection graph by record ID lives on the dedicated follows and connections modules.

createFollow

Makes one user follow another.
string
required
The user being followed (the target).
string
required
The user performing the follow (the follower).
Returns — Promise<FollowRow> — { id, user, createdAt }, where user is the followed user. Following a user the acting user already follows is not an error: it resolves with the existing follow, the same record a new follow gives, so a repeat is safe.

deleteFollow

Makes one user unfollow another.
string
required
The user being unfollowed (the target).
string
required
The user performing the unfollow (the follower).
Returns — Promise<void>

fetchFollowStatus

Checks whether the acting user follows the target user.
string
required
The user whose follow relationship is being checked (the target).
string
required
The user whose perspective the status is from.
Returns — Promise<FollowStatus>
follow is present only when the acting user follows the target; its user is the target. See FollowStatus.

requestConnection

Sends a connection request from the acting user to the target user.
string
required
The user the connection is requested with (the target).
string
required
The user sending the request (the requester).
string
Optional message to include with the request.
Returns — Promise<ConnectionRow> — the pending request, with type: "sent" and user = the target. See ConnectionRow. When a connection already exists, a request the acting user sent that is still pending, or an accepted connection, resolves to that row, so a repeat is safe (the stored message is kept). A request the target already sent the acting user rejects with 409 connection/request-received; the error body carries that request as connection, so you can accept it instead. After the target declined the acting user’s request it rejects with 409 connection/request-declined.

fetchConnectionStatus

Returns the connection status between the acting user and the target user.
string
required
The other user in the connection (the target).
string
required
The user whose perspective the status is from.
Returns — Promise<ConnectionStatus>
isConnected is true only once the connection is accepted. connection is present whenever a connection exists between the two users, pending and declined included; read its status and type to tell a request the acting user sent from one they received. See ConnectionStatus.

removeConnectionByUserId

Removes the connection between the acting user and the target user — withdrawing a sent request, declining a received one, or disconnecting an accepted connection, depending on the current state. Withdrawing and disconnecting delete the connection; a received request is declined and kept as declined.
string
required
The other user in the connection (the target).
string
required
The user withdrawing, declining, or disconnecting.
Returns — Promise<void>. It resolves with no value in every case.

Acting on a user’s blocks

User-to-user blocking is part of the trust & safety moderation bundle. These functions require that bundle; a project without it returns 403 database/tables-not-available. Each acts on behalf of one user (the blocker) — pass that user’s ID as actingUserId.
Blocking severs interaction between two users across every Sublay surface and is non-disclosing — the blocked user is never notified. See Moderation — Blocking for the full enforcement behavior.

createBlock

Blocks one user on behalf of another. On a new block, existing follows and connections between the pair are torn down (both directions) in one transaction. Idempotent — re-blocking succeeds. Self-block is rejected.
string
required
The user being blocked (the target).
string
required
The user performing the block (the blocker).
Returns — Promise<BlockRow> — { id, user, createdAt }, where user is the blocked user. Re-blocking returns the existing block. See BlockRow.

deleteBlock

Removes a block on behalf of the blocker. Idempotent; restores nothing.
string
required
The user being unblocked (the target).
string
required
The user performing the unblock (the blocker).
Returns — Promise<void>

fetchBlockStatus

Checks whether the acting user blocks the target user. Outbound-only — it never reveals whether the target has blocked the acting user.
string
required
The user whose block relationship is being checked (the target).
string
required
The user whose outbound perspective the status is from (the blocker).
Returns — Promise<BlockStatus>
block is present only when the acting user blocks the target; its user is the target. See BlockStatus.

fetchBlockedUsers

Returns a paginated list of the users the acting user has blocked (their outbound blocks), each row carrying a public profile summary. This block list is private to the blocker.
string
required
The user the service key acts as, whose own block list to read (the blocker).
number
Page number (1-indexed). Defaults to 1.
number
Results per page: a whole number from 1 to 100. Defaults to 20. A larger value is rejected with 400 block/invalid-query, never lowered to 100.
Returns — Promise<PaginatedResponse<BlockRow>>, where each BlockRow is { id, user, createdAt } and user is the blocked user.