Skip to main content
The spaces module includes a full set of membership management functions. Use these to build admin tools, automate onboarding flows, or enforce membership policies server-side. Members are addressed by their user id. The acting user’s own membership is checked with checkMyMembership and left with leaveSpace (GET / DELETE /spaces/:spaceId/members/me); the functions that take a userId (updateMemberRole, approveMembership, declineMembership, banMember, unbanMember) act on another member, and a userId equal to actingUserId is refused with 400 space/own-member-id. The space’s owner (its userId: the creator of a top-level space, the root space’s creator for a sub-space) stays an admin for good: they can’t step down, leave the space, or be banned.

joinSpace

Joins a space as the user named in actingUserId. If the space requires approval (requireJoinApproval: true), the membership is created in a pending state. A private space can’t be joined: joining a space the user can’t see answers 404 space/not-found. Its moderators and admins add members with addMember.
string
required
The Sublay space ID.
string
required
The user the service key acts as: the user who joins.
Returns — Promise<SpaceMember>: the membership record, { id, spaceId, userId, role, status, joinedAt, createdAt } (see SpaceMember). status is "pending" when the space requires approval. A user who is already an active member, or already asked to join, gets their existing membership back unchanged, so a repeat join is safe: it resolves with the same record a fresh join would. The response carries no permissions: fetch the space again to read its memberPermissions after joining.

leaveSpace

Removes a member from a space, acting as that member (DELETE /spaces/:spaceId/members/me). The space’s owner can’t leave (409 space/owner-cannot-leave).
string
required
The Sublay space ID.
string
required
The member who leaves: the request acts as them, and they must be an active member of the space.
Returns — Promise<void>. It resolves with no value once the user has left. Fetch the space again to read its memberPermissions, what the user may still do in it as a non-member.

checkMyMembership

Returns the membership status of a user in a space (GET /spaces/:spaceId/members/me). A user with a membership gets it back whatever its status (a banned user learns they’re banned); a user with no membership in a space they can’t see gets 404 space/not-found.
string
required
The Sublay space ID.
string
required
The user the service key acts as, whose membership is checked.
Returns — Promise<CheckMyMembershipResponse>: { isMember, role?, status?, joinedAt?, permissions }. role and joinedAt are present only when isMember is true, and status only when a membership record exists; a field that doesn’t apply is left out, never null. Its permissions come from the same calculation as a fetched space’s memberPermissions.

fetchSpaceMembers

Returns a paginated list of approved members in a space.
Open to anyone who can read the space. A members-only space, or a space under one, answers 403 space/membership-required to a user who isn’t an active member of that members-only space or of a space between it and this one.
string
required
The Sublay space ID.
number
Page number (1-indexed). Defaults to 1.
number
The number of members to return per page: a whole number from 1 to 100. Defaults to 20. A larger value is rejected with 400 space/invalid-query, never lowered to 100.
string
Filter by role: "admin", "moderator", or "member".
string
Filter by membership status: "pending", "active", "banned", or "rejected" (declined join requests). Honoured only when the user named by actingUserId is an admin or moderator of the space. Admins and moderators who leave status out get members of every status. Anyone else always gets active members only, whatever status they send.
string
The user to list as, exactly as their own access token: a members-only space’s list is open to them only as an active member. Omit it for the anonymous view (a members-only space returns 403 space/membership-required).
Returns — Promise<SpaceMembersResponse>

fetchSpaceTeam

Returns the admin and moderator members of a space (the “team”).
Open to anyone who can read the space. A members-only space, or a space under one, answers 403 space/membership-required to a user who isn’t an active member of that members-only space or of a space between it and this one.
string
required
The Sublay space ID.
string
The user to read as, exactly as their own access token: a members-only space’s team is open to them only as an active member. Omit it for the anonymous view (a members-only space returns 403 space/membership-required).
Returns — Promise<SpaceTeamResponse>

updateMemberRole

Updates another member’s role within a space. Only the space’s owner can promote or demote admins, and nobody can demote the owner.
string
required
The Sublay space ID.
string
required
The user the request acts as: they must be an admin of the space, and the action is recorded as theirs.
string
required
The user id of the member to update. An id equal to actingUserId is refused (400 space/own-member-id).
string
required
The new role to assign: "admin", "moderator", or "member".
Returns — Promise<SpaceMember>: the membership record, { id, spaceId, userId, role, status, joinedAt, createdAt } (see SpaceMember).

addMember

Adds a user to a space directly: they become an active member at once, with no request or approval step. This is how users get into a private space, which can’t be joined. A user with a pending or rejected membership becomes active; one who is already an active member is left as they are. A banned user can’t be added until unbanned (409 space/member-banned), nor can a user banned in a parent space (409 space/banned-in-parent). A user can’t be added when there is a block between them and the adder, in either direction (404 space/user-not-found, the same answer as for a user who doesn’t exist), or when they are suspended (403 space/user-cannot-be-added). The added user gets a space-member-added notification. See Add Member for every case and error.
string
required
The Sublay space ID.
string
required
The user the request acts as: they must be an active moderator or admin of the space, and the action is recorded as theirs.
string
required
The user to add.
Returns — Promise<SpaceMember>: the membership record, { id, spaceId, userId, role, status, joinedAt, createdAt } (see SpaceMember), with status: "active". role is member for a user just added; one who was already an active member keeps their role. It resolves with the same record whether the user was just added or already was an active member, so a repeat is safe.

approveMembership

Approves a pending membership request. Only relevant when the space has requireJoinApproval: true.
string
required
The Sublay space ID.
string
required
The user the request acts as: they must be a moderator or admin of the space, and the action is recorded as theirs.
string
required
The user id of the pending member. An id equal to actingUserId is refused (400 space/own-member-id).
Returns — Promise<SpaceMember>: the membership record, { id, spaceId, userId, role, status, joinedAt, createdAt } (see SpaceMember), with status: "active".

declineMembership

Declines and removes a pending membership request.
string
required
The Sublay space ID.
string
required
The user the request acts as: they must be a moderator or admin of the space, and the action is recorded as theirs.
string
required
The user id of the pending member. An id equal to actingUserId is refused (400 space/own-member-id).
Returns — Promise<SpaceMember>: the membership record, { id, spaceId, userId, role, status, joinedAt, createdAt } (see SpaceMember), with status: "rejected".

banMember

Bans another member from a space, preventing them from rejoining. A moderator can ban only regular members; only the space’s owner can ban an admin, and the owner can’t be banned.
string
required
The Sublay space ID.
string
required
The user the request acts as: they must be a moderator or admin of the space, and the action is recorded as theirs.
string
required
The user id of the member to ban. An id equal to actingUserId is refused (400 space/own-member-id).
string
Why the member is banned; kept in the space’s ban log.
Returns — Promise<SpaceMember>: the membership record, { id, spaceId, userId, role, status, joinedAt, createdAt } (see SpaceMember), with status: "banned".

unbanMember

Removes a ban, allowing the user to rejoin the space.
string
required
The Sublay space ID.
string
required
The user the request acts as: they must be a moderator or admin of the space, and the action is recorded as theirs.
string
required
The user id of the member to unban. An id equal to actingUserId is refused (400 space/own-member-id).
Returns — Promise<SpaceMember>: the membership record, { id, spaceId, userId, role, status, joinedAt, createdAt } (see SpaceMember), with status: "active".