WHAT YOU'LL LEARN
  • What the Webiny SDK is and when to use it
  • How to install and initialize the SDK
  • Core concepts: Result pattern, fields parameter, TypeScript generics

Overview
anchor

The Webiny SDK (@webiny/sdk) is a TypeScript library providing a programmatic interface to interact with your Webiny instance from external JavaScript or TypeScript applications like Next.js, Vue, SvelteKit, or Node.js scripts.

When to Use the SDK
anchor

The SDK is for external applications that need to read or write content from Webiny. This is different from:

  • Admin extensions - Building within the Webiny Admin UI
  • API extensions - Adding backend logic via Lambda extensions

Use the SDK when your frontend or backend application lives outside Webiny and needs to interact with Webiny’s content.

Installation
anchor

Install the package:

Initialize once with your API credentials:

lib/webiny.ts
Finding Your API Endpoint

Run yarn webiny info in your Webiny project to find your API endpoint URL. Use the base domain (e.g., https://xxx.cloudfront.net), not the full path.

What the SDK Provides
anchor

The SDK provides access to Webiny applications through namespaced modules:

ModuleWebiny AppOperations
sdk.cmsHeadless CMSList, get, create, update, publish, unpublish entries

Authentication
anchor

The SDK authenticates using an API key token generated in the Webiny Admin application (Settings → API Keys). Without a valid token, all SDK calls are rejected.

API Keys in Webiny AdminAPI Keys in Webiny Admin
(click to enlarge)

API keys have configurable permissions for each Webiny application (Headless CMS, File Manager, etc.).

Core Concepts
anchor

Result Pattern
anchor

Every SDK method returns a Result object instead of throwing errors. Check success with isOk():

This makes error handling explicit—you can’t accidentally forget to handle failures.

Fields Parameter
anchor

The fields parameter specifies which fields to return, keeping responses lean:

When omitted, the SDK returns all fields. The depth parameter (default: 1) controls how deeply reference fields are resolved.

TypeScript Generics
anchor

SDK methods accept generic type parameters for fully typed returns:

SDK Modules
anchor

CMS Module
anchor

Access Headless CMS content:

Error Handling
anchor

All SDK methods return Result objects. Always check for errors:

Best Practices
anchor

Environment Variables
anchor

Store credentials in environment variables:

.env

Singleton Instance
anchor

Create one SDK instance and reuse it:

lib/webiny.ts

Import this instance throughout your application.

Type Safety
anchor

Define interfaces for your content models:

types/product.ts

Use generics with SDK calls:

Field Selection
anchor

Only request fields you need:

GraphQL Alternative
anchor

The SDK is a convenience layer over GraphQL. You can use GraphQL directly if preferred:

The SDK handles query construction, authentication headers, and error parsing automatically.