> ## 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.

# Spaces

> Create, fetch, update, and navigate spaces from the browser

Spaces are containers — communities for organizing content. The `spaces` module covers the space lifecycle and navigation: creating spaces, looking them up by ID, slug, or short ID, updating settings, and traversing parent-child hierarchies.

For membership management see [Space Members](https://docs.sublay.io/v7/js-sdk/spaces-members.md), and for moderation and rules see [Space Moderation](https://docs.sublay.io/v7/js-sdk/spaces-moderation.md).

***

### createSpace

Creates a new space.

```typescript theme={null}
const space = await sublay.spaces.createSpace({
  name: "Photography",
  slug: "photography",
  description: "A community for photographers",
  postingPermission: "members",
});
```

**name** `string` *required*

Display name for the space.

**slug** `string`

URL-friendly identifier. Must be unique within the project. Generated from `name` if omitted.

**description** `string`

Short description of the space.

**readingPermission** `string`

Who may read content, for your app to enforce: `"anyone"` or `"members"`. The v7 API reports it in `memberPermissions.canRead` but doesn't hide the content inside the space; see [Content inside a space](https://docs.sublay.io/v7/data-models/space.md#content-inside-a-space) and the [v8 rules](https://docs.sublay.io/v8/data-models/space.md#who-can-read-content).

**postingPermission** `string`

Who may post entities, for your app to enforce: `"anyone"`, `"members"`, or `"admins"`. The v7 API reports it in `memberPermissions.canPost` but doesn't refuse entities that don't match it; see [Content inside a space](https://docs.sublay.io/v7/data-models/space.md#content-inside-a-space) and the [v8 rules](https://docs.sublay.io/v8/data-models/space.md#who-can-post-and-take-part).

**visibility** `string`

Listing/discoverability: `"public"` (default), `"unlisted"`, or `"private"`. Independent of `readingPermission`. `"unlisted"` hides the space from discovery and search but keeps it reachable by direct link; `"private"` hides the space, and the spaces under it, from everyone except its active members — it answers `404` like a nonexistent space and can't be joined. The content inside it stays readable in v7; see [Content inside a space](https://docs.sublay.io/v7/data-models/space.md#content-inside-a-space) and the [v8 rules](https://docs.sublay.io/v8/data-models/space.md#who-can-read-content).

**requireJoinApproval** `boolean`

When `true`, join requests must be manually approved.

**nsfw** `boolean`

The space's own NSFW flag. Defaults to `false`. A space created under an NSFW parent is effectively NSFW regardless of this value. See [Space NSFW flagging](https://docs.sublay.io/v7/data-models/space.md#nsfw-flagging).

**parentSpaceId** `string`

Makes this space a child of the specified parent space.

**metadata** `Record\<string, any\>`

Arbitrary metadata attached to the space.

**Returns** — `Promise<Space>`

***

### fetchSpace

Fetches a single space, including detailed information, by its ID.

```typescript theme={null}
const space = await sublay.spaces.fetchSpace({ spaceId: "spc_abc123" });
```

**spaceId** `string` *required*

The Sublay space ID.

**Returns** — `Promise<SpaceDetailed>`

***

### fetchManySpaces

Fetches a paginated, filterable list of spaces.

```typescript theme={null}
const { data, pagination } = await sublay.spaces.fetchManySpaces({
  sortBy: "members",
  parentSpaceId: "null",
  limit: 20,
});
```

**page** `number`

The page number to fetch.

**limit** `number`

The number of spaces to return per page.

**sortBy** `string`

Sort order: `"alphabetical"`, `"newest"`, or `"members"`.

**searchSlug** `string`

Filter by matching slug.

**searchName** `string`

Filter by matching name.

**searchDescription** `string`

Filter by matching description.

**searchAny** `string`

Filter by matching across slug, name, and description.

**memberOf** `string`

Pass `"true"` to return only spaces you belong to.

**parentSpaceId** `string`

Filter by parent space. Pass `"null"` for top-level spaces.

**nsfwFilter** `"include-all" | "exclude" | "only"`

Filter by each space's `nsfwEffective` (own flag OR any ancestor). `"include-all"` (default) adds no predicate; `"exclude"` drops effective-NSFW spaces; `"only"` returns only them. `"only"` may return an NSFW child whose safe parent is omitted. See [Space NSFW flagging](https://docs.sublay.io/v7/data-models/space.md#nsfw-flagging).

**include** `string`

Comma-separated related resources to include in the response.

**Returns** — `Promise<PaginatedResponse<Space>>`

***

### fetchSpaceBySlug

Fetches a detailed space by its slug.

```typescript theme={null}
const space = await sublay.spaces.fetchSpaceBySlug({ slug: "photography" });
```

**slug** `string` *required*

The space slug.

**Returns** — `Promise<SpaceDetailed>`

***

### fetchSpaceByShortId

Fetches a detailed space by its short ID.

```typescript theme={null}
const space = await sublay.spaces.fetchSpaceByShortId({ shortId: "a1b2c3" });
```

**shortId** `string` *required*

The space short ID.

**Returns** — `Promise<SpaceDetailed>`

***

### fetchUserSpaces

Fetches the spaces the logged-in user belongs to.

```typescript theme={null}
const userSpaces = await sublay.spaces.fetchUserSpaces({
  role: "admin,moderator",
  sortBy: "newest",
});
```

**page** `number`

The page number to fetch.

**limit** `number`

The number of spaces to return per page.

**sortBy** `string`

Sort order: `"alphabetical"`, `"newest"`, or `"members"`.

**include** `string`

Comma-separated related resources to include in the response.

**role** `string`

Filter by role. A single role or a comma-separated list, e.g. `"admin,moderator"`.

**status** `string`

Membership status to list: `"active"` (default), `"pending"`, or `"banned"`. Use `"pending"` to find join requests still awaiting approval.

**all** `string`

Pass `"true"` or `"false"`.

**Returns** — `Promise<UserSpacesResponse>`

***

### fetchMutualSpaces

Fetches the spaces the logged-in user shares with another user — the spaces both are active members of.

```typescript theme={null}
const mutual = await sublay.spaces.fetchMutualSpaces({
  userId: "usr_other",
  page: 1,
  limit: 20,
});
```

**userId** `string` *required*

The other user's ID. Mutual spaces are computed between this user and the logged-in user.

**page** `number`

The page number to fetch.

**limit** `number`

The number of spaces to return per page. Max `100`.

**include** `string`

Comma-separated related resources to include (e.g. `"files"`).

**Returns** — `Promise<PaginatedResponse<Space>>`

***

### updateSpace

Updates a space's settings.

```typescript theme={null}
const space = await sublay.spaces.updateSpace({
  spaceId: "spc_abc123",
  description: "An updated description",
  postingPermission: "admins",
});
```

**spaceId** `string` *required*

The Sublay space ID.

**name** `string`

New display name for the space.

**slug** `string`

New URL-friendly identifier.

**description** `string`

New description of the space.

**readingPermission** `string`

Who may read content, for your app to enforce: `"anyone"` or `"members"`. The v7 API reports it in `memberPermissions.canRead` but doesn't hide the content inside the space; see [Content inside a space](https://docs.sublay.io/v7/data-models/space.md#content-inside-a-space) and the [v8 rules](https://docs.sublay.io/v8/data-models/space.md#who-can-read-content).

**postingPermission** `string`

Who may post entities, for your app to enforce: `"anyone"`, `"members"`, or `"admins"`. The v7 API reports it in `memberPermissions.canPost` but doesn't refuse entities that don't match it; see [Content inside a space](https://docs.sublay.io/v7/data-models/space.md#content-inside-a-space) and the [v8 rules](https://docs.sublay.io/v8/data-models/space.md#who-can-post-and-take-part).

**visibility** `string`

Updated visibility: `"public"`, `"unlisted"`, or `"private"`. Controls listing/discoverability, independent of `readingPermission`.

**nsfw** `boolean`

Updated NSFW own-flag. Toggling it recomputes this space's effective NSFW and cascades it top-down to every descendant space (and, live, to their entities). See [Space NSFW flagging](https://docs.sublay.io/v7/data-models/space.md#nsfw-flagging).

**metadata** `Record\<string, any\>`

Arbitrary metadata attached to the space.

**Returns** — `Promise<Space>`

***

### deleteSpace

Deletes a space.

```typescript theme={null}
const result = await sublay.spaces.deleteSpace({ spaceId: "spc_abc123" });
```

**spaceId** `string` *required*

The Sublay space ID.

**Returns** — `Promise<DeleteSpaceResponse>`

***

### checkSlugAvailability

Checks whether a space slug is available.

```typescript theme={null}
const { available } = await sublay.spaces.checkSlugAvailability({
  slug: "photography",
});
```

**slug** `string` *required*

The slug to check.

**Returns** — `Promise<{ available: boolean }>`

***

### fetchChildSpaces

Fetches a paginated list of child spaces under a parent.

```typescript theme={null}
const { data, pagination } = await sublay.spaces.fetchChildSpaces({
  spaceId: "spc_abc123",
  sortBy: "alphabetical",
});
```

**spaceId** `string` *required*

The parent space ID.

**page** `number`

The page number to fetch.

**limit** `number`

The number of spaces to return per page.

**sortBy** `string`

Sort order: `"alphabetical"`, `"newest"`, or `"members"`.

**include** `string`

Comma-separated related resources to include in the response.

**Returns** — `Promise<PaginatedResponse<Space>>`

***

### fetchSpaceBreadcrumb

Fetches the ancestor breadcrumb chain for a space.

```typescript theme={null}
const breadcrumb = await sublay.spaces.fetchSpaceBreadcrumb({
  spaceId: "spc_abc123",
});
```

**spaceId** `string` *required*

The Sublay space ID.

**Returns** — `Promise<SpaceBreadcrumb>`

***

### getSpaceConversation

Gets the chat conversation object associated with a space.

```typescript theme={null}
const conversation = await sublay.spaces.getSpaceConversation({
  spaceId: "spc_abc123",
});
```

**spaceId** `string` *required*

The Sublay space ID.

**Returns** — `Promise<Conversation>`

> [!NOTE]
>
> Space chat messages are sent and read via the [chat](https://docs.sublay.io/v7/js-sdk/chat.md) module.


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