WHAT YOU'LL LEARN
  • How to define TypeScript types for your content models?
  • How to query entries using the Webiny SDK?
  • How to create, update, and delete entries?
  • How to handle errors with the Result pattern?

Overview
anchor

This guide covers practical examples of working with Headless CMS content using the Webiny SDK. The SDK is the recommended way to interact with a Webiny instance from external JavaScript or TypeScript applications such as Next.js, Vue, SvelteKit, or Node.js scripts. It provides type-safe methods for querying and mutating content, with automatic API selection and built-in error handling.

Prerequisites
anchor

  • Webiny SDK initialized in your project
  • API key with appropriate permissions (read-only or full-access)
  • At least one content model created in Headless CMS

Defining TypeScript Types
anchor

Define interfaces that match your content model structure. Field names must match the field IDs (not labels) from your content model:

lib/types.ts

Key points:

  • Field names match field IDs from content model
  • Reference fields use CmsEntryData<T> type
  • Optional fields use ? suffix

Pass your interface as a generic to SDK methods for full type safety:

Querying Entries
anchor

List All Entries
anchor

Sorting Results
anchor

Sort options:

  • values.{fieldId}_ASC - Ascending order
  • values.{fieldId}_DESC - Descending order
  • createdOn_ASC / createdOn_DESC - Sort by creation date
  • savedOn_ASC / savedOn_DESC - Sort by last saved date

Filtering Results
anchor

Common filter operators:

  • _eq - Equals
  • _ne - Not equals
  • _in - In array
  • _not_in - Not in array
  • _lt - Less than
  • _lte - Less than or equal
  • _gt - Greater than
  • _gte - Greater than or equal
  • _contains - Contains substring
  • _not_contains - Does not contain substring

Pagination

Get Single Entry
anchor

Working With Reference Fields
anchor

To retrieve data from a referenced entry, include the nested field paths in fields. Reference field values are accessed via values.{referenceField}.values.{nestedField}:

Mutating Entries
anchor

Creating Entries
anchor

Important:

  • createEntry() uses the Manage API
  • Entry is created in draft status
  • Call publishEntry() to make it publicly visible

Updating Entries
anchor

Note: updateEntry() only modifies the specified fields. Other fields remain unchanged.

Publishing Entries
anchor

Publishing makes an entry available via the Read API. Unpublished (draft) entries are only accessible via the Manage API.

Deleting Entries
anchor

Error Handling
anchor

All SDK methods return a Result type. Always check for errors before accessing the value:

Common error scenarios:

  • Entry not found (entryId does not exist)
  • Permission denied (API key lacks permissions)
  • Validation errors (required fields missing)
  • Network errors (API unreachable)