> ## Documentation Index
> Fetch the complete documentation index at: https://docs.sublay.io/llms.txt
> Use this file to discover all available pages before exploring further.

# Fetch My Spaces

> Get the spaces the signed-in user is a member of

Returns a paginated list of spaces a user has a membership in — the signed-in user, or with a service key the user named by `actingUserId` — along with their membership details for each space. Every space the user is an active member of is listed, whatever its visibility (`public`, `unlisted` or `private`), so this is the endpoint for a "my spaces" screen. A `pending`, `banned` or `rejected` membership of a space the user can't see (a private space, or one under a private space they aren't a member of) is left out, and doesn't count toward the total; [Fetch Spaces](https://docs.sublay.io/v8/api-reference/spaces/fetch-spaces.md) lists public spaces only. By default only active memberships are returned; use `status` to list pending join requests or spaces the user was banned from. `query` searches within the user's spaces.

## Query Parameters

**actingUserId** `string`

Service key only, and required with one: the user this request acts as, whose spaces are listed. A user token always acts as its own user and must not send it (`400 space/acting-user-not-allowed`).

**status** `string`

Membership status to list: `"active"` (default), `"pending"`, or `"banned"`.

`"pending"` surfaces join requests still awaiting admin approval — useful for a "waiting to join" screen on spaces that have `requireJoinApproval` enabled.

**page** `number`

Page number. Defaults to `1`.

**limit** `number`

Results per page. Max `100`.

**query** `string`

Free-text search term, matched as a case-insensitive substring, the same way as on [Fetch Spaces](https://docs.sublay.io/v8/api-reference/spaces/fetch-spaces.md). Trimmed; a blank value returns `400 space/invalid-query`. Leave it out for no text filtering.

**searchFields** `string`

The one field `query` is matched against: `"slug"`, `"name"` or `"description"`. Left out, `query` matches the slug, the name or the description. Values match exactly; any other value returns `400 space/invalid-query`.

**sortBy** `string`

Sort order: `"joinedAt"` (when the user joined), `"createdAt"` (when the space was created), `"alphabetical"` (by name) or `"members"` (by active member count). Defaults to `"joinedAt"`. Ties are broken by a stable order, so pages neither repeat nor skip a space.

**sortDir** `string`

Direction, `"asc"` or `"desc"` (either case), for any `sortBy`. Left out: A–Z for `"alphabetical"`, otherwise newest / most first.

**role** `string`

Filter by role. Single value (`"admin"`, `"moderator"`, `"member"`) or comma-separated list (e.g. `"admin,moderator"`).

**parentSpaceId** `string`

Narrows the list by where each space sits in the tree. `none` lists the user's memberships in top-level spaces only (spaces with no parent). A space id lists their memberships in that space's direct sub-spaces; an id that matches no space returns an empty page, not a 404. `any`, left out, or sent empty: memberships at every level are listed. This is the default, because membership is per space. `none` and `any` match exactly (`ANY` is refused). `null` and `undefined` are refused with `400 space/unsupported-param` (see [Saying "no value"](https://docs.sublay.io/v8/authentication.md#saying-no-value)). Any other value that isn't a space id returns `400 space/invalid-query`.

`none` goes by the space, not by what the user belongs to: a membership in a sub-space whose parent the user isn't a member of is still not top-level, so `none` leaves it out. To show such a sub-space too, list every level and group the results yourself.

**include** `string`

Associations to include, as a comma-separated value or repeated params. The only value is:

* `files` — the processed `avatarFile` and `bannerFile` objects on each space (requires the `files-images` bundle)

Matching ignores case. An unknown value returns `400 space/invalid-query`.

**all** `string`

Pass `"true"` to return all memberships without pagination. When used, the response omits the `pagination` field.

## Response

**data** `MySpaceItem[]`

Each item contains a `space` and a `membership` object.

**membership properties**

**membershipId** `string`

Membership record UUID.

**role** `string`

`"admin"`, `"moderator"`, or `"member"`.

**status** `string`

`"active"`, `"pending"`, or `"banned"` — matches the requested `status` filter.

**joinedAt** `Date`

When the membership was created.

**pagination** `object`

Standard pagination metadata.

## Error Responses

> [accordion] Not signed in — 401 / 403
>
> Returned with no JSON body: `401` when no `Authorization` header is sent, `403` when the access token is invalid or expired.

> [accordion] Unsupported sort — 400
>
> `sortBy=newest` is rejected with a pointer to the two sorts it could mean: `sortBy=createdAt` (newest spaces first) or `sortBy=joinedAt` (the default, most recently joined first).
>
> ```json theme={null}
> {
>   "error": "`sortBy=newest` isn't supported in v8. Use `sortBy=createdAt` to list the newest spaces first, or `sortBy=joinedAt` (the default) to list the spaces the user joined most recently first.",
>   "code": "space/unsupported-param",
>   "param": "sortBy"
> }
> ```

> [accordion] Unsupported parentSpaceId value — 400
>
> `parentSpaceId=null` and `parentSpaceId=undefined` are rejected with the spelling to use instead.
>
> ```json theme={null}
> {
>   "error": "`parentSpaceId=null` isn't supported. Use `parentSpaceId=none` for top-level spaces, or `parentSpaceId=any` for every level (the default).",
>   "code": "space/unsupported-param",
>   "param": "parentSpaceId"
> }
> ```

> [accordion] Invalid query — 400
>
> Returned with code `space/invalid-query` for invalid values — for example an unknown `sortBy`, `sortDir`, `searchFields` or `include` value, a blank `query`, or an `actingUserId` that isn't a valid UUID. `error` names the first problem found.
>
> ```json theme={null}
> { "error": "include: Unknown include `members`. Allowed: files.", "code": "space/invalid-query" }
> ```

> [accordion] Missing User — 400
>
> A service key sent no `actingUserId`.
>
> ```json theme={null}
> { "error": "A service key must send actingUserId: the user this request acts as.", "code": "space/missing-user-id" }
> ```

> [accordion] Acting User Not Allowed — 400
>
> A user token sent `actingUserId`, even naming its own user. Only a service key names the user it acts as; a user token always acts as its own user.
>
> ```json theme={null}
> { "error": "actingUserId is only accepted with a service key. A user's own token always acts as that user.", "code": "space/acting-user-not-allowed" }
> ```

> [accordion] User Not Found — 404
>
> Returned when a service key names an `actingUserId` that isn't a user in this project.
>
> ```json theme={null}
> { "error": "No user with this actingUserId exists in this project.", "code": "space/user-not-found" }
> ```

> [accordion] Unsupported Parameter — 400
>
> The request sent `userId`. On this route the user a service key acts as is `actingUserId`.
>
> With a service key:
>
> ```json theme={null}
> {
>   "error": "`userId` was renamed to `actingUserId`: send the user this service key acts as in `actingUserId`.",
>   "code": "space/unsupported-param",
>   "param": "userId"
> }
> ```
>
> With a user token, or with no credentials:
>
> ```json theme={null}
> {
>   "error": "`userId` isn't accepted here: a user's own token always acts as that user.",
>   "code": "space/unsupported-param",
>   "param": "userId"
> }
> ```

> [accordion] Unsupported Route — 400
>
> `GET /spaces/user-spaces` is not a v8 route. It answers with a pointer to this endpoint.
>
> ```json theme={null}
> {
>   "error": "`GET /spaces/user-spaces` isn't supported in v8. List your spaces with `GET /spaces/mine`.",
>   "code": "space/unsupported-route"
> }
> ```

See also: [useFetchMySpaces](https://docs.sublay.io/v8/hooks/spaces/use-fetch-my-spaces.md)


This documentation is built and hosted on [Mintlify](https://mintlify.com), a developer documentation platform.