Skip to main content
The collections module manages a user’s saved-content collections. Every user has a single root collection, under which they can nest sub-collections and into which they can save entities.
Collections are always scoped to a specific user. Pass that user’s Sublay ID as actingUserId, the user your service key acts as, on every call.
A collection’s entityCount counts the entities that user can see in it, by the same rule as the totalItems of its entities list, so the two always match: entities that are deleted, removed by moderation, back in drafts, or in a space they can’t read (see who can read content) aren’t counted or listed, though they stay saved. Saving an entity in a space they can’t read fails with 404 entity/not-found. See Collection → entityCount.

fetchRootCollection

Fetches a user’s root collection, creating it on first access if it does not yet exist.
string
required
The user the service key acts as, whose root collection to fetch.
Returns — Promise<Collection>

fetchSubCollections

Fetches the direct child collections nested under a given collection.
string
required
The parent collection ID.
string
required
The user the service key acts as, who owns the collection.
Returns — Promise<{ data: Collection[] }> — the direct children, oldest first, each with its entityCount.

createNewCollection

Creates a new sub-collection under an existing parent collection.
string
required
The parent collection under which to create the sub-collection.
string
required
The name of the new collection. Trimmed; 1 to 255 characters after trimming.
string
required
The user the service key acts as, who will own the collection.
Returns — Promise<Collection>

fetchCollectionEntities

Fetches a paginated list of entities saved in a collection.
string
required
The collection ID.
string
required
The user the service key acts as, who owns the collection.
number
Page number (1-indexed). Defaults to 1.
number
The number of entities to return per page: a whole number from 1 to 100. Defaults to 20. A larger value is rejected with 400 collection/invalid-query, never lowered to 100.
string
Sort order: "createdAt" (creation date), "addedAt" (when saved), "top" (reaction count), or "hot" (engagement score).
string
Which reaction top ranks by: "upvote", "downvote", "like", "love", "wow", "sad", "angry", or "funny". Defaults to "upvote". Only valid with sortBy: "top" — the server rejects it with any other sort.
string
Sort direction: "asc" or "desc". Not accepted with "hot", which ranks one way only.
CollectionEntityIncludeParam
Associations to populate: "user", "space", "topComments", "files", "grants" (a single value or an array). "saved" isn’t accepted — every returned entity is in this collection.
number
With include containing "topComments": how many top comments per entity. Server default 1, maximum 5. Rejected (400) without "topComments" in include.
ReactionType
With include containing "topComments": the reaction whose raw count ranks the top comments. Server default "upvote". Rejected (400) without "topComments" in include.
Returns — Promise<PaginatedResponse<Entity>>

addEntityToCollection

Saves an entity into a collection.
string
required
The collection to add the entity to.
string
required
The Sublay entity ID to save.
string
required
The user the service key acts as, who owns the collection.
Returns — Promise<{ id: string; name: string; entityCount: number }>: the collection’s summary after the save. The same whether the entity was just added or already in the collection, so a repeat save is safe.

removeEntityFromCollection

Removes an entity from a collection.
string
required
The collection to remove the entity from.
string
required
The Sublay entity ID to remove.
string
required
The user the service key acts as, who owns the collection.
Returns — Promise<{ id: string; name: string; entityCount: number }>: the collection’s summary after the removal, whether or not the entity was in it.

updateCollection

Renames a collection.
string
required
The collection ID to update.
string
required
The user the service key acts as, who owns the collection.
string
required
The new collection name. Must be a non-empty string.
Returns — Promise<Collection>

deleteCollection

Deletes a collection and every collection under it, at any depth. The root collection can’t be deleted.
string
required
The collection ID to delete.
string
required
The user the service key acts as, who owns the collection.
Returns — Promise<{ deletedCollectionIds: string[] }>: the deleted collection and every collection under it. See Delete Collection.