webiny-sdk
できること
外部のアプリをWebinyのヘッドレスなコンテンツシステムに接続し、コンテンツを取得、作成、更新、公開する方法を示します。Webinyからコンテンツを得るウェブサイトやアプリを作る開発者向けです。
使う場面
- ✓Webinyのコンテンツが必要なNext.js、Vue、またはNode.jsのアプリを作っている開発者がいるとき。
- ✓コードからWebinyのコンテンツのエントリーを公開または非公開にしたいとき。
- ✓外部のアプリで、Webinyのコンテンツを絞り込み、並べ替え、ページ送りする必要があるとき。
スキルのリンク
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/webiny-sdk/SKILL.mdコピーしてAI(Claude、ChatGPT、Cursor)に貼り付け、指示に従うよう頼んでください。
使い方
いちばん簡単な方法:メッセージをコピーしてAIに貼り付けるだけ。AIがスキルを読んで指示に従います。
貼り付け用メッセージ
Claude Code、Codex、Cursorの場合:プロジェクトのフォルダで実行するとスキルがインストールされます。
SKILL.mdをダウンロードして、エージェントのスキル用フォルダに入れてください。
AIへの頼み方の例
“Next.jsのサイトに、Webinyからブログの記事を取得するにはどうすればよいですか?”
毎週5つの新しいスキル。1分で読めます。
仕組み
スキルは、トークンとエンドポイントを使ってSDKを設定する方法を示します。その後、エントリーを一覧、取得、作成、更新、または公開するメソッドを呼びます。すべての呼び出しは、コードが確認する結果を返します。
技術的な内容(元のSKILL.md)
作者による元のテキスト(英語)をGitHubからそのまま表示しています。
Webiny SDK
TL;DR
The @webiny/sdk package provides a TypeScript interface for external apps (Next.js, Vue, Node.js) to interact with Webiny's Headless CMS and File Manager. Every method returns a Result object (checked with isOk()). Supports listing, getting, creating, updating, publishing, and unpublishing entries with filtering, sorting, pagination, and TypeScript generics for type safety.
Installation & Setup
npm install @webiny/sdk
Initialize once and reuse:
// lib/webiny.ts
import { Webiny } from "@webiny/sdk";
export const webiny = new Webiny({
token: process.env.WEBINY_API_TOKEN!,
endpoint: process.env.WEBINY_API_ENDPOINT!,
tenant: process.env.WEBINY_API_TENANT || "root"
});
token-- API key token generated in Webiny Admin (Settings > API Keys)endpoint-- The base API URL, without a trailing slash. Runyarn webiny infoin your Webiny project to find the API URL. For Website Builder projects useNEXT_PUBLIC_WEBSITE_BUILDER_API_HOST.tenant-- Tenant ID, defaults to"root"
IMPORTANT: Never add a trailing slash to
endpoint. The SDK appends/graphqlto the endpoint internally, sohttps://xxx.cloudfront.net/will break all requests.
The fields Parameter (Required)
Every SDK method requires a fields array that specifies which fields to return. Omitting it will cause a runtime error.
- Use
"values.<fieldId>"for content fields:"values.name","values.price" - Use top-level field names for metadata:
"id","entryId","createdOn","status" - Use dot notation for nested fields:
"values.author.name"
// Minimal fields -- just IDs
fields: ["id", "entryId"];
// Content fields
fields: ["id", "entryId", "values.name", "values.price", "values.description"];
// Nested reference fields
fields: ["id", "values.title", "values.author.name", "values.author.email"];
CMS: Read vs Preview Mode
webiny.cms.listEntries and webiny.cms.getEntry accept a preview parameter to control which revisions are returned:
preview |
Returns | Use For |
|---|---|---|
false (default) |
Published entries only | Public-facing apps, SSG |
true |
Latest revision (draft or published) | Content preview, editorial tools |
Write operations (createEntry, updateEntryRevision, etc.) are not affected by preview.
The Result Pattern
Every SDK method returns a Result object -- it never throws:
const result = await webiny.cms.listEntries({
modelId: "product",
fields: ["id", "values.name"]
});
if (result.isOk()) {
console.log(result.value.data); // success -- typed data
} else {
console.error(result.error.message); // failure -- error info
}
TypeScript Generics
Pass a type parameter for full type safety on values:
import type { CmsEntryData } from "@webiny/sdk";
interface Product {
name: string;
price: number;
sku: string;
description: string;
category?: CmsEntryData<ProductCategory>;
}
interface ProductCategory {
name: string;
slug: string;
}
const result = await webiny.cms.listEntries<Product>({
modelId: "product",
fields: ["id", "entryId", "values.name", "values.price", "values.sku"]
});
if (result.isOk()) {
// result.value.data is CmsEntryData<Product>[]
const products = result.value.data;
// products[0].values.name -- fully typed
}
Reference fields like category are typed as CmsEntryData<T>, which wraps referenced entries with id, entryId, and values.
Reading Data
List Entries
const result = await webiny.cms.listEntries<Product>({
modelId: "product",
fields: ["id", "entryId", "values.name", "values.price"],
sort: { "values.name": "asc" },
limit: 10
});
List with Filters
const result = await webiny.cms.listEntries<Product>({
modelId: "product",
fields: ["id", "entryId", "values.name", "values.price"],
where: {
"values.price_gte": 100,
"values.name_contains": "Pro"
},
sort: { "values.price": "desc" }
});
Filter Operators
| Operator | Description | Example |
|---|---|---|
_eq |
Equals (default) | `"values.status |
よくある質問
APIのトークンとエンドポイントはどこで見つけますか?
トークンはWebinyの管理画面のAPIキーで作られます。エンドポイントは、プロジェクトでinfoコマンドを実行して見つけるよう、スキルは述べています。
なぜすべての呼び出しで、フィールドの一覧を指定する必要があるのですか?
各SDKのメソッドには、何を返すかを指定するフィールドの一覧が必要です。省くと、コードの実行時にエラーになると、スキルは警告しています。
エンドポイントの末尾はスラッシュで終わるべきですか?
いいえ。末尾のスラッシュはすべてのリクエストを壊すと、スキルは警告しています。
詳細
作者による元の説明
Using @webiny/sdk to read and write CMS data from external applications. Use this skill when the developer is building a Next.js, Vue, Node.js, or any external app that needs to fetch or write content to Webiny, set up the SDK, use the Result pattern, list/get/create/update/publish entries, filter and sort queries, use TypeScript generics for type safety, work with the File Manager, list languages, trigger or monitor background tasks, or create API keys programmatically. Covers read vs preview mode, the `values` wrapper requirement, correct method names, and the `fields` required parameter, an
repo: webiny/webiny-js
人気
- GitHubのスター
- 8.1k
- ランキング
- #12617
- ライセンス
- —
- 更新日
- 2026/11/2
コメント
- …
このリポジトリの他のスキル
prd-to-plan
8.1k製品要件書を、それぞれ端から端まで成立する小さなスライスの段階的な計画に変え、Markdownファイルとして保存するよう、エージェントを支援します。
webiny-admin-architect
8.1kビジネスロジックの層とプレゼンターのパターンを使い、Webinyプラットフォームの管理画面を作る方法をエージェントに教えます。
webiny-admin-permissions
8.1k自動生成される権限フォームや、表示・非表示のチェックを含め、Webinyの管理画面に権限の制御を追加するよう、エージェントに教えます。
webiny-form-model
8.1kビルダーで宣言的にフィールドを定義し、レイアウト、検証、条件付きのルールを使って、Webinyのフォームを作るよう、エージェントに教えます。
似ているスキル
api-connector-builder
280kエージェントが既存のパターンに従って、新しいAPI連携を構築します。新しい方式を作らずに、もう一つ連携を追加したいときに使います。
api-design
280kエージェントがベストプラクティスに沿ってREST APIを設計できるようにします。APIの通信方法、エラーの表示方法、データの整理方法を決めるのに役立ちます。
backend-patterns
280kエージェントのサーバーサイドのアーキテクチャパターンとデータベースの最適化を支援します。サーバー上で動くコードを作成またはレビューするときに役立ちます。