Skip to main content
Fetch Entity by Foreign ID
Requires the entities bundle. A project without the entities bundle returns 403 database/tables-not-available. See Bundles.
Returns an entity matching the given foreignId within the project. Optionally creates a blank entity if none exists — useful for automatically bootstrapping entities when a user first visits a page or URL in your application.

Query Parameters

string
required
The foreign ID to look up. This is the identifier from your application (URL, slug, database ID, etc.).
string
Service key only: the user to read as. The response is exactly what that user’s own access token would get — their own drafts, block filtering, saved, their own reaction and the top comments they may see — and the read counts as their view. Leave it out for the anonymous view: drafts return 404, and the read doesn’t count as a view. It shapes the read only: an entity made by createIfNotFound is always app-owned, with no author. A user token always acts as its own user and must not send it, and neither may a request with no credentials (400 entity/acting-user-not-allowed).
string
When "true", creates a blank entity with this foreignId if no entity is found. The new entity has no title, content, or author (an app-owned entity), whoever asks. Defaults to "false".Because the new entity has no author, the project’s Who can create entities without an author setting decides who may create it:A refused caller gets 403 entity/authorless-creation-not-allowed and nothing is created. A user token that is expired or invalid counts as no credentials, so under Signed-in users only that caller is refused too. A suspended user can’t create the entity: they get 403 user/suspended, as on Create Entity. The setting only matters when the entity doesn’t exist yet: reading an existing entity works for every caller. Requests that race to create the same foreignId all get the one entity that was created. A foreignId whose entity was deleted stays taken: the lookup answers 409 entity/foreign-id-taken instead of creating a new entity. A project admin changes the setting in the dashboard under Settings → General → SDK.
string
Associations to include. Pass it as one comma-separated value (include=user,space) or as repeated params (include=user&include=space). Values:
  • user — the author’s user profile
  • space — the space the entity belongs to (null when the viewer can’t see that space; see Space visibility)
  • topComments — the entity’s best top-level comments, as full Comment objects (see Top comments)
  • saved — whether the authenticated user has saved this entity
  • files — uploaded file/image attachments
  • grants — the reputation-grant summary for the entity
number
default:"1"
With include=topComments: how many top comments per entity. A whole number of at least 1 — 0, a negative number or a non-integer value returns 400 entity/invalid-query. Maximum 5 — larger values are treated as 5.
string
default:"upvote"
With include=topComments: the reaction whose raw count ranks the top comments (ties newest first). One of upvote, downvote, like, love, wow, sad, angry, funny.
include values are case-insensitive. An unknown value returns 400 entity/invalid-query, as does sending topCommentsLimit or topCommentsSortByReaction without include=topComments. topComments lists real content only — deleted, removed and block-edged comments are left out — and is [] when nothing qualifies.

Response

Returns an Entity object.
This endpoint returns entities regardless of moderation status, so the client can display the appropriate moderation state. Draft entities are only returned to their author: a user token, or a service key naming the author in actingUserId.

Error Responses

Returned with code entity/invalid-query for an unknown include value, when topCommentsLimit is below 1 or not a whole number, or when topCommentsLimit / topCommentsSortByReaction is sent without include=topComments.
include=topComment is rejected with a pointer to its replacement.
Returned when no entity with this foreignId exists and createIfNotFound is not "true".
createIfNotFound was "true" and the entity with this foreignId was deleted. A foreignId is unique across the project’s entities, deleted ones included, so a deleted entity’s foreignId can’t be reused. Nothing is created.
Returned when your entity.created validation webhook rejects the entity that createIfNotFound would create. error carries the message your webhook returned. Nothing is stored.
createIfNotFound was "true", no entity with this foreignId exists, and the project’s Who can create entities without an author setting doesn’t let this caller create one: a request with no credentials under Signed-in users only or No one from the client, or a user token under No one from the client. The message names the caller.
For a user token, the message reads signed-in users in place of anonymous callers.
createIfNotFound was "true", no entity with this foreignId exists, and the caller’s user is suspended: the signed-in user, or the user a service key names in actingUserId. Nothing is created. Reading an existing entity is not affected.
reason is null when none was given; endDate is null for a suspension with no end date.
A user token, or a request with no credentials, sent actingUserId, even naming its own user. Only a service key names the user it acts as; a user token always acts as its own user.
Returned when a service key names an actingUserId that isn’t a user in this project.