Reference > SDK > Overview
Webiny SDK Reference
API reference for the Webiny SDK — a type-safe JavaScript/TypeScript client for interacting with Webiny.
WHAT YOU'LL LEARN
- How to initialize the Webiny SDK?
- What configuration options are available?
- What sub-SDKs are available and what they do?
Overview
The Webiny SDK is a type-safe JavaScript/TypeScript client for interacting with a Webiny instance from external applications — Node.js scripts, Next.js, Vue, SvelteKit, and others.
Install it from npm:
yarn add @webiny/sdkInitialization
Create a Webiny instance with your endpoint and API token:
import { Webiny } from "@webiny/sdk";
const sdk = new Webiny({
endpoint: "https://your-webiny-endpoint.com",
token: "your-api-token",
tenant: "root" // optional, defaults to "root"
});Configuration
| Option | Type | Required | Description |
|---|---|---|---|
endpoint | string | Yes | The URL of your Webiny API endpoint |
token | string | No | API token for authentication |
tenant | string | No | Tenant ID. Defaults to "root" |
headers | Record<string, string> | No | Additional HTTP headers sent with every request |
fetch | typeof fetch | No | Custom fetch implementation. Defaults to the global fetch |
Sub-SDKs
| Property | Class | Description |
|---|---|---|
sdk.cms | CmsSdk | Query and mutate Headless CMS entries |
sdk.fileManager | FileManagerSdk | Upload and manage files |
sdk.languages | LanguagesSdk | Retrieve configured languages |
sdk.tenantManager | TenantManagerSdk | Create and manage tenants |
sdk.tasks | TasksSdk | Trigger and manage background tasks |
Error Handling
All SDK methods return a Result<TValue, TError> type. Use result.isOk() and result.isFail() to branch on success or failure:
const result = await sdk.cms.getEntry({
modelId: "article",
where: { entryId: "abc" },
fields: ["id"]
});
if (result.isFail()) {
console.error(result.error.message);
return;
}
console.log(result.value); // typed as CmsEntryData<TValues>Error Types
| Error class | code | When thrown |
|---|---|---|
HttpError | HTTP_ERROR | The API responded with a non-2xx HTTP status |
GraphQLError | GRAPHQL_ERROR | The API returned a GraphQL-level error |
NetworkError | NETWORK_ERROR | The fetch call itself threw (e.g. no connectivity) |