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.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.Associations to populate, as a single value or an array. The only value is
"files", which populates avatarFile and bannerFile.Promise<User>
fetchUserByForeignId
Fetches a user profile by your application’s own user identifier. It only reads: a user that doesn’t exist throws a404. To create the user when missing, use fetchOrCreateUserByForeignId.
Your application’s user identifier, matched exactly as sent. A blank or whitespace-only one is refused with
400 user/invalid-query.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.Associations to populate, as a single value or an array. The only value is
"files", which populates avatarFile and bannerFile.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.
Your application’s user identifier, kept exactly as sent. A blank or whitespace-only one is refused with
400 user/invalid-body.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").Public metadata, a JSON object — used only when creating a new user. The whole request body can be at most 100 KB.
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.
Associations to populate, as a single value or an array. The only value is
"files", which populates avatarFile and bannerFile.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.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.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.Associations to populate, as a single value or an array. The only value is
"files", which populates avatarFile and bannerFile.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).
New username. Must be available: a username another user already holds throws a
409 (user/username-taken, with param: "username").New avatar URL, stored as given;
null clears it. Separate from avatarFile, which uploads an image.Updated public metadata. Replaces the stored object; send the whole object, including keys you aren’t changing.
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.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".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.A new banner image, replacing the current one; same shape as
avatarFile.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).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, anduserDeletedAt 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.
Promise<void>
fetchUserSuggestions
Returns users whose name or username matches a partial query string. Useful for mention autocomplete on the server.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.
Promise<{ data: User[] }>
checkUsernameAvailability
Checks whether a username is available for registration.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.The user to read the history as: the result is exactly what their own access token would get. Omit for the anonymous view.
Only comments on entities from this source, or
"none" for comments on entities with no source. Left out: any source.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.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.Server default
"createdAt". "top" ranks by the raw count of sortByReaction.Applies to
"createdAt" and "top"; not accepted with "controversial", which ranks one way only. Server default "desc".Related data to populate:
"user", "entity", "space", "parent", "grants", "files" (the comment’s images and files; requires the files-images bundle).Promise<CursorPaginatedResponse<Comment>> — { data, pagination: { nextCursor, hasMore } }
fetchFollowersByUserId
Returns a paginated list of the specified user’s followers.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.
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.Optional search term. Filters the list to users whose username or name contains this text (case-insensitive). When omitted, no filtering is applied.
Restricts which field
query matches against — username or name. When omitted, query matches either field.Promise<PaginatedResponse<FollowRow>> — each FollowRow is { id, user, createdAt }, where user is the follower.
fetchFollowersCountByUserId
Returns the total number of followers for a user.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.
Promise<{ count: number }>
fetchFollowingByUserId
Returns a paginated list of users that the specified user is following.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.
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.Optional search term. Filters the list to users whose username or name contains this text (case-insensitive). When omitted, no filtering is applied.
Restricts which field
query matches against — username or name. When omitted, query matches either field.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.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.
Promise<{ count: number }>
fetchConnectionsByUserId
Returns a paginated list of a user’s accepted connections.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.
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.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.
Restricts which field
query matches against — username or name. When omitted, query matches either field.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.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.
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.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.Promise<void>
fetchFollowStatus
Checks whether the acting user follows the target user.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.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.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.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 returns403 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.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.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.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.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.Promise<PaginatedResponse<BlockRow>>, where each BlockRow is { id, user, createdAt } and user is the blocked user.
