Skip to main content
Entities are the core content objects in Sublay — posts, articles, products, or any item in your application that users interact with. The entities module gives you full server-side control over their lifecycle.

createEntity

Creates a new entity.
string
Your application’s identifier for this entity. Used for idempotent lookups via fetchEntityByForeignId.
string
An optional secondary identifier for grouping or filtering entities.
string
The space this entity belongs to.
string
Title text for the entity.
string
Body/content text for the entity.
array
File or media attachments.
string[]
Tags or keywords used for filtering and discovery.
array
User mentions embedded in the entity.
object
Geographic coordinates { latitude: number; longitude: number }.
object
Arbitrary public metadata.
string
The Sublay user ID to set as the entity’s author.
boolean
When true, the entity is created as an unpublished draft. Defaults to false.
boolean
When true, creates the entity with no author association even if userId is provided.
boolean
When true, the request fails unless a valid author user is resolved.
Date
A Date used to backdate the entity’s creation time.
Date
A Date used to backdate the entity’s last update time.
ReturnsPromise<Entity>

fetchEntity

Fetches a single entity by its Sublay ID.
string
required
The Sublay entity ID.
string
Comma-separated list of associations to populate.
string
Opts the returned entity’s author into a spaceReputation number. Accepts a space <uuid>, "none" (the project-general bucket), or "context" (the space derived from the request context). The empty string and the legacy general / null aliases are rejected. See Reputation.
boolean
Only honored alongside an explicit space <uuid>. When true, spaceReputation is the subtree sum — the named space plus all of its descendants.
ReturnsPromise<Entity>

fetchEntityByForeignId

Fetches an entity by your application’s own identifier. Optionally creates it if not found.
string
required
Your application’s entity identifier.
boolean
When true, creates a stub entity if no match is found. Defaults to false.
string
Comma-separated list of associations to populate.
ReturnsPromise<Entity>

fetchEntityByShortId

Fetches an entity by its short, human-readable ID (used in share URLs).
string
required
The entity’s short ID.
string
Comma-separated list of associations to populate.
ReturnsPromise<Entity>

fetchManyEntities

Fetches a filtered, paginated list of entities. Supports rich filtering by metadata, keywords, location, and more.
string
Filter by source ID.
string
Filter to entities within a specific space.
string
Sort order: "createdAt" (chronological — honors sortDir), "hot" (trending), "top" (highest scored), or "controversial". A "metadata.<prop>" value is also accepted to sort by a metadata field.
string
Sort direction: "asc" or "desc".
string
How to interpret a metadata sort value: "auto", "numeric", "text", "boolean", or "timestamp".
string
Sort by the count of a specific reaction: "upvote", "downvote", "like", "love", "wow", "sad", "angry", or "funny".
number
Page number (1-indexed). Defaults to 1.
number
Results per page. Defaults to 20.
string
Comma-separated list of associations to populate (e.g. "user").
string
Time window to restrict results to: "hour", "day", "week", "month", or "year".
string
The viewing user, used to resolve followedOnly.
"true" | "false"
When "true", returns only entities from users the given userId follows.
object
Filter by keyword tags: { includes?: string[]; doesNotInclude?: string[] }.
object
Filter by metadata fields: { includes?, includesAny?, doesNotInclude?, exists?: string[], doesNotExist?: string[] }.
object
Filter by title: { hasTitle?: "true" | "false"; includes?: string | string[]; doesNotInclude?: string | string[] }.
object
Filter by content: { hasContent?: "true" | "false"; includes?: string | string[]; doesNotInclude?: string | string[] }.
object
Filter by attachments: { hasAttachments?: "true" | "false" }.
object
Filter within a geographic radius: { latitude: string; longitude: string; radius: string }.
string
Opts each returned entity’s author into a spaceReputation number. Accepts a space <uuid>, "none" (the project-general bucket), or "context" (the space derived from the request context — resolved per-row from the space each entity belongs to). The empty string and the legacy general / null aliases are rejected. See Reputation.
boolean
Only honored alongside an explicit space <uuid>. When true, spaceReputation is the subtree sum — the named space plus all of its descendants.
ReturnsPromise<PaginatedResponse<Entity>>

updateEntity

Updates fields on an existing entity.
string
required
The Sublay entity ID to update.
string
New title.
string
New content body.
array
Updated attachments list.
string[]
Updated keywords list.
object
Updated coordinates { latitude: number; longitude: number }.
object
Updated metadata. Merged with existing values.
array
Updated user mentions list.
ReturnsPromise<Entity>

deleteEntity

Permanently deletes an entity and its associated data.
string
required
The Sublay entity ID to delete.
ReturnsPromise<void>

incrementEntityViews

Increments the view counter on an entity. Call this when a user views content to track engagement.
string
required
The Sublay entity ID.
number
Number to add to the view counter. Defaults to 1.
ReturnsPromise<Entity>

fetchDrafts

Fetches a user’s unpublished draft entities.
string
required
The Sublay user ID whose drafts to fetch.
number
Page number (1-indexed). Defaults to 1.
number
Results per page. Defaults to 20.
string
Filter drafts by source ID.
string
Filter drafts to a specific space.
string
Comma-separated list of associations to populate.
ReturnsPromise<PaginatedResponse<Entity>>

publishDraft

Publishes a draft entity, making it publicly visible.
string
required
The Sublay entity ID of the draft to publish.
ReturnsPromise<Entity>

fetchTopComment

Fetches the highest-scored (top) comment on an entity. Returns null if the entity has no comments.
string
required
The Sublay entity ID.
ReturnsPromise<TopComment | null>

addReaction

Adds a reaction from a user to an entity.
string
required
The Sublay entity ID.
string
required
The Sublay user ID of the reactor.
ReactionType
required
One of: "upvote", "downvote", "like", "love", "wow", "sad", "angry", "funny".
ReturnsPromise<Reaction>

removeReaction

Removes a user’s existing reaction from an entity.
string
required
The Sublay entity ID.
string
required
The Sublay user ID whose reaction to remove.
ReturnsPromise<void>

fetchReactions

Fetches a paginated list of reactions on an entity, optionally filtered by reaction type.
string
required
The Sublay entity ID.
ReactionType
Filter to a specific reaction type.
number
Page number (1-indexed). Defaults to 1.
number
Results per page. Defaults to 20.
string
Sort direction: "asc" or "desc".
string
Opts each returned reactor into a spaceReputation number. Accepts a space <uuid>, "none" (the project-general bucket), or "context" (the space derived from the request context). The empty string and the legacy general / null aliases are rejected. See Reputation.
boolean
Only honored alongside an explicit space <uuid>. When true, spaceReputation is the subtree sum — the named space plus all of its descendants.
ReturnsPromise<PaginatedResponse<Reaction>>

getUserReaction

Checks what reaction (if any) a specific user has left on an entity.
string
required
The Sublay entity ID.
string
required
The Sublay user ID to check.
ReturnsPromise<{ reactionType: ReactionType | null }>

isEntitySaved

Checks whether a user has saved an entity to any of their collections.
string
required
The Sublay entity ID.
string
required
The Sublay user ID to check.
ReturnsPromise<{ isSaved: boolean }>