Skip to main content
The collections module organizes the logged-in user’s saved content. Every user has a single root collection, under which they can nest sub-collections and into which they can save entities.

fetchRootCollection

Fetches the logged-in user’s root collection.
const root = await sublay.collections.fetchRootCollection();
ReturnsPromise<Collection>

fetchSubCollections

Fetches the immediate sub-collections of a collection.
const subCollections = await sublay.collections.fetchSubCollections({
  collectionId: "col_root123",
});
collectionId
string
required
The parent collection ID.
ReturnsPromise<Collection[]>

createNewCollection

Creates a sub-collection under a parent collection.
const collection = await sublay.collections.createNewCollection({
  collectionId: "col_root123",
  collectionName: "Recipes",
});
collectionId
string
required
The parent collection under which to create the sub-collection.
collectionName
string
required
The name of the new collection.
ReturnsPromise<Collection>

fetchCollectionEntities

Fetches the entities within a collection, paginated.
const { data, pagination } = await sublay.collections.fetchCollectionEntities({
  collectionId: "col_abc123",
  sortBy: "added",
  sortDir: "desc",
});
collectionId
string
required
The collection ID.
page
number
The page number to fetch.
limit
number
The number of entities to return per page.
sortBy
"new" | "added" | "top" | "hot"
Sort order.
sortDir
"asc" | "desc"
Sort direction.
include
string
Comma-separated related resources to include in the response.
ReturnsPromise<PaginatedResponse<Entity>>

addEntityToCollection

Adds an entity to a collection.
const result = await sublay.collections.addEntityToCollection({
  collectionId: "col_abc123",
  entityId: "ent_222",
});
collectionId
string
required
The collection ID.
entityId
string
required
The ID of the entity to add.
ReturnsPromise<{ success: boolean; collection: { id: string; entityCount: number } }>

removeEntityFromCollection

Removes an entity from a collection.
const result = await sublay.collections.removeEntityFromCollection({
  collectionId: "col_abc123",
  entityId: "ent_222",
});
collectionId
string
required
The collection ID.
entityId
string
required
The ID of the entity to remove.
ReturnsPromise<{ success: boolean; collection: { id: string; entityCount: number } }>

updateCollection

Renames a collection.
const collection = await sublay.collections.updateCollection({
  collectionId: "col_abc123",
  name: "Favorite Recipes",
});
collectionId
string
required
The collection ID.
name
string
The new collection name.
ReturnsPromise<Collection>

deleteCollection

Deletes a collection.
await sublay.collections.deleteCollection({ collectionId: "col_abc123" });
collectionId
string
required
The collection ID.
ReturnsPromise<void>