Skip to main content
The users module reads and updates user profiles and lets the logged-in user act on the social graph of an arbitrary target user, addressed by userId. In the follow and connection helpers below, userId is always the target — the user being followed, the other party in a connection, or the user whose followers you’re reading. The actor is always the logged-in token holder. To act on your own graph (your own followers, the users you follow, your own connections and pending requests), use the follows and connections modules instead.

fetchUserById

Fetches a user by their internal Sublay user ID.
string
required
The Sublay user ID.
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 by your application’s own user identifier.
string
required
Your application’s user identifier.
UserIncludeParam
Associations to populate, as a single value or an array. The only value is "files", which populates avatarFile and bannerFile.
Returns — Promise<User>

fetchUserByUsername

Fetches a user by their username.
string
required
The user’s unique username.
UserIncludeParam
Associations to populate, as a single value or an array. The only value is "files", which populates avatarFile and bannerFile.
Returns — Promise<User>

fetchUserSuggestions

Returns users whose name or username matches a partial query string. Useful for mention autocomplete.
string
required
Partial name or username to search for.
Returns — Promise<{ data: User[] }>

checkUsernameAvailability

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

updateUser

Updates a user’s profile, optionally uploading a new avatar and/or banner image. A user token may only update its own profile.
string
required
The Sublay user ID to update. A user token may only update itself.
string | null
New display name. null (or an empty string) clears it, on a call without a file.
string
New username. Must be available: a username another user already holds throws a 409 (user/username-taken, with param: "username").
string | null
New avatar URL, stored as given; null clears it, on a call without a file. Separate from avatarFile, which uploads an image.
string | null
New bio text. null (or an empty string) clears it, on a call without a file.
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, like "1990-05-17", is refused).
object
Geographic location { latitude: number; longitude: number }.
object
Updated public metadata (Record<string, any>).
object
Updated secure metadata (Record<string, any>). No API response returns it, to this user or anyone else; your backend receives it in webhooks. The user can write it themselves, so don’t store anything your app needs to trust here.
object
A new avatar image to upload, replacing the current one (up to 50 MB): { file: Blob | File; options: ImageOptions }.
object
A new banner image to upload, replacing the current one: { file: Blob | File; options: ImageOptions }.
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).
When avatarFile or bannerFile is supplied the request is sent as multipart/form-data carrying the browser File/Blob. The image options (an ImageOptions object whose mode selects a processing strategy) are sent alongside the file. A multipart field can’t carry null, so a call with a file and a null field throws before anything is sent: clear the field in a separate call without a file.
Returns — Promise<AuthUser>

fetchCommentsByUserId

Returns a user’s comments — top-level comments and replies alike, across entities — cursor-paginated. See Fetch Comments by User for which comments the list contains.
string
required
The Sublay user ID whose comments to fetch.
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 the viewer is block-edged with are treated. "exclude" (default) leaves them out; "include-outbound-blocked" re-includes only the viewer’s own outbound-blocked authors, marked isAuthorBlocked: true. No effect without the moderation bundle.
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 target user’s followers.
string
required
The Sublay user ID whose followers to fetch.
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 the target user.
string
required
The Sublay user ID.
Returns — Promise<{ count: number }>

fetchFollowingByUserId

Returns a paginated list of users that the target user is following.
string
required
The Sublay user ID whose following list to fetch.
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 target user is following.
string
required
The Sublay user ID.
Returns — Promise<{ count: number }>

fetchConnectionsByUserId

Returns a paginated list of the target user’s accepted connections.
string
required
The Sublay user ID whose connections to fetch.
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 target user’s connection.

fetchConnectionsCountByUserId

Returns the number of accepted connections for the target user.
string
required
The Sublay user ID.
Returns — Promise<{ count: number }>

createFollow

The logged-in user follows the target user.
string
required
The user being followed (the target).
Returns — Promise<FollowRow> — { id, user, createdAt }, where user is the followed user. Following a user the logged-in 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

The logged-in user unfollows the target user.
string
required
The user being unfollowed (the target).
This unfollows by the target’s userId. To delete one of your own follow relationships by its record ID, use follows.deleteFollow, which takes a followId.
Returns — Promise<void>

fetchFollowStatus

Returns whether the logged-in user follows the target user.
string
required
The user whose follow relationship is being checked (the target).
Returns — Promise<FollowStatus>
follow is present only when the logged-in user follows the target; its user is the target. See FollowStatus.

requestConnection

Sends a connection request from the logged-in user to the target user.
string
required
The user the connection is requested with (the target).
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 logged-in 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 logged-in 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 logged-in user’s request it rejects with 409 connection/request-declined.

fetchConnectionStatus

Returns the connection status between the logged-in user and the target user.
string
required
The other user in the connection (the target).
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 logged-in user sent from one they received. See ConnectionStatus.

removeConnectionByUserId

Removes the connection with 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).
Returns — Promise<void>. It resolves with no value in every case.

Blocking

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. The blocker is the token holder — there is no 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 a user. On a new block, existing follows and connections between the pair are torn down (both directions). Idempotent — re-blocking succeeds. Self-block is rejected server-side.
string
required
The user being blocked (the target). The blocker is the token holder.
Returns — Promise<BlockRow> — { id, user, createdAt }, where user is the blocked user. Re-blocking returns the existing block. See BlockRow.

deleteBlock

Unblocks a user. Idempotent; restores nothing.
string
required
The user being unblocked (the target).
Returns — Promise<void>

fetchBlockStatus

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

fetchBlockedUsers

Returns a paginated list of the users the token holder has blocked (their outbound blocks), each row carrying a public profile summary. This block list is private to 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.