WHAT YOU'LL LEARN
  • How to query entries from the Headless CMS using sdk.cms?
  • How to create, update, publish, and delete CMS entries?
  • How to use TypeScript generics for type-safe entry data?
  • How to handle the Result pattern in CMS operations?

Overview
anchor

The CmsSdk class provides methods for interacting with Headless CMS entries from external applications. Access it via sdk.cms on a Webiny instance. All read operations use the Read API by default (published content only), while write operations use the Manage API. Methods return Result objects—check for success with isOk() before accessing values.

Read Methods

  • getEntry — fetch a single entry by ID or filter
  • listEntries — list entries with filtering, sorting, and pagination

Write Methods

CmsSdk
anchor

The CmsSdk class is instantiated automatically when you create a Webiny instance. Access it via the cms property.

getEntry
anchor

Retrieves a single entry from the CMS by ID, entry ID, or custom field values.

Parameters
anchor

NameTypeRequiredDescription
paramsGetEntryParamsYesParameters for retrieving the entry
params.modelIdstringYesThe model ID of the entry to retrieve
params.whereGetEntryWhereYesFilter conditions for finding the entry
params.where.idstringNoThe revision ID (e.g., "abc123#0001")
params.where.entryIdstringNoThe entry ID (e.g., "abc123")
params.where.valuesRecord<string, unknown>NoFilter by entry field values
params.fieldsstring[]YesFields to include in response. Use "values.fieldId" for entry values or top-level fields like "id", "createdOn"
params.previewbooleanNoWhen true, uses Preview API to access unpublished/draft content. When false (default), uses Read API for published content only

Return Type
anchor

Result<CmsEntryData<TValues>, HttpError | GraphQLError | NetworkError>

Returns a Result containing the entry data on success or an error on failure.

Example
anchor

listEntries
anchor

Lists entries from the CMS with support for filtering, sorting, pagination, and full-text search.

Parameters
anchor

NameTypeRequiredDescription
paramsListEntriesParamsYesParameters for listing entries
params.modelIdstringYesThe model ID of entries to list
params.whereRecord<string, unknown>NoFilter conditions using operators like _eq, _gt, _contains, etc.
params.sortRecord<string, "asc" \| "desc">NoSort configuration (e.g., { "values.name": "asc" })
params.limitnumberNoMaximum number of entries to return (default: 10)
params.afterstringNoCursor for pagination from previous response
params.searchstringNoFull-text search term to filter entries across searchable fields (text, longText fields with fullTextSearch enabled)
params.fieldsstring[]YesFields to include in response. Use "values.fieldId" for entry values or top-level fields like "id", "createdOn"
params.previewbooleanNoWhen true, uses Preview API to access unpublished/draft content. When false (default), uses Read API for published content only

Return Type
anchor

Result<ListEntriesResult<TValues>, HttpError | GraphQLError | NetworkError>

Returns a Result containing an object with:

  • data: Array of CmsEntryData<TValues> objects
  • meta: Pagination metadata (cursor, hasMoreItems, totalCount)

Example
anchor

createEntry
anchor

Creates a new entry in the CMS. The entry is created in draft status—call publishEntryRevision to make it publicly visible.

Parameters
anchor

NameTypeRequiredDescription
paramsCreateEntryParams<TValues>YesParameters for creating the entry
params.modelIdstringYesThe model ID for the entry
params.dataCreateCmsEntryData<TValues>YesThe entry data to create. Must include values object with field data
params.fieldsstring[]YesFields to include in response. Use "values.fieldId" for entry values or top-level fields like "id", "createdOn"

Return Type
anchor

Result<CreateCmsEntryData<TValues>, HttpError | GraphQLError | NetworkError>

Returns a Result containing the created entry data on success or an error on failure.

Example
anchor

updateEntryRevision
anchor

Updates an existing entry revision in the CMS. Only the specified fields in data.values are modified—other fields remain unchanged.

Parameters
anchor

NameTypeRequiredDescription
paramsUpdateEntryRevisionParams<TValues>YesParameters for updating the entry revision
params.modelIdstringYesThe model ID for the entry
params.revisionIdstringYesThe revision ID of the entry to update (e.g., "abc123#0001")
params.dataUpdateCmsEntryData<TValues>YesThe updated entry data. Use values for field updates
params.fieldsstring[]YesFields to include in response. Use "values.fieldId" for entry values or top-level fields like "id", "createdOn"

Return Type
anchor

Result<UpdateCmsEntryData<TValues>, HttpError | GraphQLError | NetworkError>

Returns a Result containing the updated entry data on success or an error on failure.

Example
anchor

publishEntryRevision
anchor

Publishes an entry revision, making it available via the Read API. Published entries are visible to public consumers of your content.

Parameters
anchor

NameTypeRequiredDescription
paramsPublishEntryRevisionParamsYesParameters for publishing the entry revision
params.modelIdstringYesThe model ID of the entry to publish
params.revisionIdstringYesThe revision ID of the entry to publish (e.g., "abc123#0001")
params.fieldsstring[]YesFields to include in response. Use "values.fieldId" for entry values or top-level fields like "id", "createdOn"

Return Type
anchor

Result<CmsEntryData<TValues>, HttpError | GraphQLError | NetworkError>

Returns a Result containing the published entry data on success or an error on failure.

Example
anchor

unpublishEntryRevision
anchor

Unpublishes an entry revision, reverting it to draft status and removing it from the Read API.

Parameters
anchor

NameTypeRequiredDescription
paramsUnpublishEntryRevisionParamsYesParameters for unpublishing the entry revision
params.modelIdstringYesThe model ID of the entry to unpublish
params.revisionIdstringYesThe revision ID of the entry to unpublish (e.g., "abc123#0001")
params.fieldsstring[]YesFields to include in response. Use "values.fieldId" for entry values or top-level fields like "id", "createdOn"

Return Type
anchor

Result<CmsEntryData<TValues>, HttpError | GraphQLError | NetworkError>

Returns a Result containing the unpublished entry data on success or an error on failure.

Example
anchor

deleteEntryRevision
anchor

Deletes an entry revision from the CMS. By default, performs a soft delete (entry can be restored). Pass permanent: true for permanent deletion.

Parameters
anchor

NameTypeRequiredDescription
paramsDeleteEntryRevisionParamsYesParameters for deleting the entry revision
params.modelIdstringYesThe model ID of the entry to delete
params.revisionIdstringYesThe revision ID of the entry to delete (e.g., "abc123#0001")
params.permanentbooleanNoWhether to permanently delete the entry (default: false)

Return Type
anchor

Result<boolean, HttpError | GraphQLError | NetworkError>

Returns a Result containing true on success or an error on failure.

Example
anchor

Types
anchor

CmsEntryValues
anchor

Base type for entry field values. Extend this interface to define your content model structure.

CmsEntryData
anchor

Type representing a complete CMS entry with metadata and field values.

CmsEntryStatus
anchor

Entry publication status.

CmsIdentity
anchor

User identity information in entry metadata.

Practical Examples
anchor

List With Filter, Sort, and Pagination
anchor

Get Entry by ID
anchor

Create and Publish Flow
anchor

TypeScript Generics Usage
anchor

Error Handling Pattern
anchor