Skip to main content
Requires the entities bundle. A project without the entities bundle returns 403 database/tables-not-available for entity calls. See Bundles.
Entities are the central 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, with optional images and files.
string
Your application’s identifier for this entity. Used for idempotent lookups via fetchEntityByForeignId.
string | null
An optional secondary identifier for grouping or filtering entities. For no source, leave it out or pass null. "none", "null" and "undefined" are reserved and refused with 400 entity/invalid-body.
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 user the service key acts as, who authors the entity; the create runs under that user’s own checks. Omit it to create an app-owned entity with no author, which only your service key naming nobody can later edit, publish or delete. A user that doesn’t exist returns 404 entity/user-not-found.
boolean
The entity’s own NSFW flag. Defaults to false. Effective NSFW also inherits from the entity’s space. See Entity NSFW flagging.
boolean
When true, the entity is created as an unpublished draft. Defaults to false. A draft needs an owner, so it requires actingUserId (400 entity/draft-requires-user otherwise).
string | Date
Backdates the entity’s creation time: a Date, or a full UTC timestamp string such as "2024-03-01T12:00:00.000Z" (date.toISOString()). A string in another format (a date alone, or a time with an offset) is refused with 400 entity/invalid-body and param naming the field. A service key ability, also with actingUserId (for imports with original authors and dates). More than five minutes in the future returns 400 entity/invalid-body (createdAt can't be in the future.).
string | Date
Same format as createdAt, used to backdate the entity’s last update time. More than five minutes in the future returns 400 entity/invalid-body (updatedAt can't be in the future.).
{ files: { file: Uint8Array | Blob; filename?: string; mimeType?: string }[]; options: ImageOptions }
Images to attach, up to 50 MB each, processed per options (mode is required). Raw bytes carry no type, so pass mimeType with a Uint8Array (image/jpeg, image/png or image/webp; without it the file goes as application/octet-stream and is refused with 400 entity/unsupported-file-type); a Blob keeps its own type. A PDF goes in files: in images it isn’t a valid image (422 entity/invalid-image). A part without a filename is named image. With images or files, the request is sent as multipart/form-data. A request takes at most 20 files in all. Requires the files-images bundle.
{ files: { file: Uint8Array | Blob; filename?: string; mimeType?: string }[]; options?: { pathParts?: string[] } }
Files to attach, stored as uploaded (JPEG, PNG, WebP or PDF: pass mimeType with a Uint8Array), up to 50 MB each. Each file’s type comes from its MIME type; an image sent here isn’t processed, so it has no image data. A part without a filename is named file. Requires the files-images bundle.
Returns — Promise<Entity>

fetchEntity

Fetches a single entity by its Sublay ID. A removed entity is returned in full to its author and as a placeholder to everyone else.
string
required
The Sublay entity ID.
string
The user to read as: you get exactly what their own access token would get (their drafts, blocks, saved, their own reaction, top comments), and the read counts as their view. Omit it for the anonymous view (drafts return 404; no view is counted).
EntityIncludeParam
Associations to populate, as a single value or an array: "user", "space", "topComments", "saved", "files", "grants". "topComments" adds the entity’s best top-level comments as full Comment objects — see Top comments. "saved" adds saved: { isSaved, collections }, the user’s saved state for the entity — see Saved state.
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<Entity>

fetchEntityByForeignId

Fetches an entity by your application’s own identifier. It only reads: an entity that doesn’t exist throws a 404. To create the entity when missing, use fetchOrCreateEntityByForeignId. A removed entity is returned in full to its author and as a placeholder to everyone else.
string
required
Your application’s entity identifier.
string
The user to read as: you get exactly what their own access token would get (their drafts, blocks, saved, their own reaction, top comments), and the read counts as their view. Omit it for the anonymous view (drafts return 404; no view is counted).
EntityIncludeParam
Associations to populate, as a single value or an array: "user", "space", "topComments", "saved", "files", "grants". "topComments" adds the entity’s best top-level comments as full Comment objects — see Top comments. "saved" adds saved: { isSaved, collections }, the user’s saved state for the entity — see Saved state.
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<Entity>

fetchOrCreateEntityByForeignId

Returns the entity with your application’s identifier, or creates it when there is none. The entity it creates carries only the foreignId: no title, content or author (an app-owned entity). A service key may always create it, whatever the project’s Who can create entities without an author setting, except when it names a suspended user in actingUserId: that returns 403 user/suspended and nothing is created. Props type: FetchOrCreateEntityByForeignIdProps. A removed entity is returned in full to its author and as a placeholder to everyone else.
string
required
Your application’s entity identifier.
string
The user to read as, as on fetchEntityByForeignId. It shapes the read only: an entity this call creates is always app-owned. An existing entity this user can’t read comes back as 404, and nothing is created.
EntityIncludeParam
Associations to populate, as a single value or an array: "user", "space", "topComments", "saved", "files", "grants". "topComments" adds the entity’s best top-level comments as full Comment objects — see Top comments. "saved" adds saved: { isSaved, collections }, the user’s saved state for the entity — see Saved state.
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<FetchOrCreateEntityByForeignIdResult>: { entity: Entity; created: boolean }. created is true when this call created the entity (HTTP 201) and false when it already existed (HTTP 200, also when another call created it concurrently). A foreignId whose entity was deleted stays taken: the call throws 409 entity/foreign-id-taken and creates nothing. See Fetch Entity by Foreign ID.

fetchEntityByShortId

Fetches an entity by its short, human-readable ID (used in share URLs). A removed entity is returned in full to its author and as a placeholder to everyone else.
string
required
The entity’s short ID.
string
The user to read as: you get exactly what their own access token would get (their drafts, blocks, saved, their own reaction, top comments), and the read counts as their view. Omit it for the anonymous view (drafts return 404; no view is counted).
EntityIncludeParam
Associations to populate, as a single value or an array: "user", "space", "topComments", "saved", "files", "grants". "topComments" adds the entity’s best top-level comments as full Comment objects — see Top comments. "saved" adds saved: { isSaved, collections }, the user’s saved state for the entity — see Saved state.
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<Entity>

fetchManyEntities

Fetches a filtered, paginated list of entities. Supports rich filtering by metadata, keywords, location, and more.
string | "none"
Only entities from this source, or "none" for entities with no source. Left out: any source.
string | "none"
Only entities in this space, or "none" for entities in no space. Left out: any space, or none.
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". Not accepted with "hot" or "controversial", which rank one way only.
string
How to interpret a metadata sort value: "auto", "numeric", "text", "boolean", or "timestamp".
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.
number
Page number (1-indexed). Defaults to 1.
number
Results per page: a whole number from 1 to 100. Defaults to 10. A larger value is rejected with 400 entity/invalid-query, never lowered to 100.
EntityIncludeParam
Associations to populate, as a single value or an array: "user", "space", "topComments", "saved", "files", "grants". "topComments" adds the entity’s best top-level comments as full Comment objects — see Top comments. "saved" adds saved: { isSaved, collections }, the user’s saved state for the entity — see Saved state.
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.
string
Time window to restrict results to: "hour", "day", "week", "month", or "year".
string
Author filter: returns only entities authored by this user. Not the viewer: that is actingUserId.
string
The user to list as: you get exactly what their own access token would get (followedOnly and blockedFilter for them, their own removed entities when userId names them, saved, their own reactions, top comments), and the reads count as their views. Omit it for the anonymous view.
"true" | "false"
When "true", returns only entities from users the viewer (actingUserId) follows. Without actingUserId it has no effect.
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 }.
"include-all" | "exclude" | "only"
Filter by effective NSFW (entity.nsfw OR its space's nsfwEffective). "include-all" (default) adds no predicate; "exclude" drops effective-NSFW entities; "only" returns only them. See Entity NSFW flagging.
"exclude" | "include-outbound-blocked"
How to treat entities authored by users the viewer is block-edged with. "exclude" (default) hides them; "include-outbound-blocked" re-includes only the viewer’s own outbound-blocked authors — never content from users who blocked the viewer. No effect without the moderation bundle.
Returns — Promise<PaginatedResponse<Entity>>

updateEntity

Updates fields on an existing entity, as its author, and adds or removes its files.
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
Replaces the entity’s metadata wholesale (not merged).
array
Updated user mentions list.
string
The user this edit acts as. Required when the entity has an author: pass the author, and the request runs exactly as their own (400 entity/missing-user-id without it; anyone else gets 403). Omit it only for an app-owned entity.
boolean
Updated NSFW own-flag (the owner’s). A space moderator flagging another user’s entity uses spaces.setSpaceEntityNsfw instead. See Entity NSFW flagging.
{ files: { file: Uint8Array | Blob; filename?: string; mimeType?: string }[]; options: ImageOptions }
Images to append after the entity’s files, processed per options (mode is required). Raw bytes carry no type, so pass mimeType with a Uint8Array (image/jpeg, image/png or image/webp; without it the file goes as application/octet-stream and is refused with 400 entity/unsupported-file-type); a Blob keeps its own type. A PDF goes in files: in images it isn’t a valid image (422 entity/invalid-image). With images or files, the request is sent as multipart/form-data. Requires the files-images bundle.
{ files: { file: Uint8Array | Blob; filename?: string; mimeType?: string }[]; options?: { pathParts?: string[] } }
Files to append after the entity’s files, stored as uploaded (JPEG, PNG, WebP or PDF: pass mimeType with a Uint8Array). Requires the files-images bundle.
string[]
Ids of the entity’s files to remove (ids in its files). Works alone or with uploads. Any other id throws a 400 (entity/invalid-remove-file-ids, with invalidIds).
"files" | "files"[]
What the response adds: "files", the entity’s files as they now are. Without it the response has no files, even after an upload or removal.
Returns — Promise<Entity>. With include: "files", the entity carries its files as they now are.

deleteEntity

Deletes an entity and its associated data, as its author. Deleting a published entity takes back the author’s reputation for creating it, once: not for a draft, and not again for one already soft-deleted.
string
required
The Sublay entity ID to delete.
string
The user this delete acts as. Required when the entity has an author: pass the author, and the request runs exactly as their own (400 entity/missing-user-id without it; anyone else gets 403). Omit it only for an app-owned entity.
Returns — Promise<void>

incrementEntityViews

Increments the view counter on an entity. Call this when a user views content to track engagement. It always acts as your app and takes no actingUserId.
string
required
The Sublay entity ID.
number
Number to add to the view counter: an integer of at least 1. Defaults to 1. Sent as a JSON number in the request body.
Returns — Promise<EntityRecord>: the stored entity record only, without the computed fields (commentsCount, userReaction, nsfwEffective) or any included associations (user, space, files, topComments, saved, grants). Moderation details (moderationReason, moderatedById, moderatedByType) read as null.

fetchDrafts

Fetches a user’s unpublished draft entities. A draft marked removed (moderationStatus: "removed") is listed too, but it can’t be published or edited, only deleted.
string
required
The user the service key acts as, whose drafts to fetch.
number
Page number (1-indexed). Defaults to 1.
number
Results per page: a whole number from 1 to 100. Defaults to 10. A larger value is rejected with 400 entity/invalid-query, never lowered to 100.
string | "none"
Only drafts from this source, or "none" for drafts with no source. Left out: any source.
string | "none"
Only drafts in this space, or "none" for drafts in no space. Left out: any space, or none.
DraftIncludeParam
Associations to populate: "user", "space", "files", "grants" (a single value or an array).
Returns — Promise<PaginatedResponse<Entity>>

publishDraft

Publishes a draft entity as its author, making it publicly visible.
string
required
The Sublay entity ID of the draft to publish.
string
required
The user this publish acts as: the draft’s author, and the request runs exactly as their own (400 entity/missing-user-id without it; anyone else gets 403). A draft with no author, which this API never creates, is answered as not found (404 entity/not-found).
Returns — Promise<Entity>

addReaction

Adds a reaction from a user to an entity.
string
required
The Sublay entity ID.
string
required
The user the service key acts as: the reacting user.
ReactionType
required
One of: "upvote", "downvote", "like", "love", "wow", "sad", "angry", "funny".
Returns — Promise<Entity> — the updated entity, as the reacting user sees it: userReaction and reactionCounts reflect the new reaction.

removeReaction

Removes a user’s existing reaction from an entity. It sends DELETE /entities/:entityId/reactions with actingUserId in the query and no body. A removed entity is returned in full to its author and as a placeholder to everyone else.
string
required
The Sublay entity ID.
string
required
The user the service key acts as, whose reaction to remove.
Returns — Promise<Entity> — the updated entity, as that user sees it. When the user has no reaction on the entity, the entity comes back unchanged. If the entity’s author has blocked the user, this fails with 404 entity/not-found and nothing changes.

fetchReactions

Fetches a paginated list of reactions on an entity, optionally filtered by reaction type.
string
required
The Sublay entity ID.
string
The user to list as, exactly as their own access token: reactions from users they are block-edged with are left out, and an entity whose author blocked them fails with 404 entity/not-found. Omit it for the anonymous view.
ReactionType
Filter to a specific reaction type.
number
Page number (1-indexed). Defaults to 1.
number
Results per page: a whole number from 1 to 100. Defaults to 20. A larger value is rejected with 400 entity/invalid-query, never lowered to 100.
string
Sort direction: "asc" or "desc".
Returns — Promise<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 user the service key acts as, whose reaction is checked.
Returns — Promise<{ reactionType: ReactionType | null }> If the entity’s author has blocked the user, this fails with 404 entity/not-found.