webiny-sdk
Skill này làm gì
Chỉ cách kết nối một ứng dụng bên ngoài với hệ thống nội dung headless của Webiny để lấy, tạo, cập nhật và xuất bản nội dung. Dành cho lập trình viên xây website hoặc ứng dụng lấy nội dung từ Webiny.
Khi nào nên dùng
- ✓Khi lập trình viên đang xây ứng dụng Next.js, Vue hoặc Node.js cần nội dung từ Webiny.
- ✓Khi lập trình viên muốn xuất bản hoặc gỡ xuất bản một mục nội dung Webiny bằng code.
- ✓Khi lập trình viên cần lọc, sắp xếp hoặc phân trang nội dung Webiny trong ứng dụng bên ngoài.
Liên kết skill
https://github.com/webiny/webiny-js/blob/next/skills/user-skills/webiny-sdk/SKILL.mdSao chép rồi dán vào AI của bạn (Claude, ChatGPT hoặc Cursor) và nhờ nó làm theo hướng dẫn.
Cách dùng
Cách dễ nhất: sao chép tin nhắn và dán vào AI của bạn. AI sẽ đọc skill và làm theo hướng dẫn.
Tin nhắn có sẵn để dán
Dành cho Claude Code, Codex hoặc Cursor: chạy lệnh trong thư mục dự án của bạn và skill sẽ được cài đặt.
Tải tệp SKILL.md về và thả vào thư mục skill của agent.
Ví dụ cách nhờ AI
“Làm sao để lấy các bài blog từ Webiny vào trang Next.js của tôi?”
5 skill mới mỗi tuần. Đọc chỉ 1 phút.
Cách hoạt động
Skill chỉ cách thiết lập SDK với token và endpoint, rồi gọi các phương thức để liệt kê, lấy, tạo, cập nhật hoặc xuất bản mục. Mỗi lần gọi đều trả về kết quả mà code phải kiểm tra.
Nội dung kỹ thuật (SKILL.md gốc)
Lấy nguyên văn từ GitHub, do tác giả viết bằng tiếng Anh.
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 |
Câu hỏi thường gặp
Tôi lấy API token và endpoint ở đâu?
Token được tạo trong admin Webiny, mục API keys. Skill nói endpoint tìm bằng cách chạy lệnh info trong dự án của bạn.
Vì sao phải liệt kê trường trong mọi lần gọi?
Mỗi phương thức SDK cần một danh sách trường để nói rõ cần trả về gì. Skill cảnh báo rằng bỏ qua sẽ gây lỗi khi code chạy.
Endpoint có nên kết thúc bằng dấu gạch chéo không?
Không. Skill cảnh báo rằng dấu gạch chéo cuối sẽ làm hỏng mọi yêu cầu.
Chi tiết
Mô tả gốc của tác giả
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
Độ phổ biến
- Sao GitHub
- 8.1k
- Vị trí xếp hạng
- #12617
- Giấy phép
- —
- Cập nhật
- 2/11/2026
Bình luận
- …
Thêm skill từ kho mã này
prd-to-plan
8.1kGiúp agent của bạn biến tài liệu yêu cầu sản phẩm thành kế hoạch theo giai đoạn gồm các lát cắt đầu-cuối nhỏ, lưu thành file Markdown.
webiny-admin-architect
8.1kDạy agent của bạn cách xây dựng màn hình quản trị cho nền tảng Webiny, dùng các tầng logic nghiệp vụ và mẫu presenter.
webiny-admin-permissions
8.1kDạy agent của bạn thêm kiểm soát quyền vào màn hình quản trị Webiny, gồm form quyền tự sinh và kiểm tra ẩn hoặc hiện.
webiny-form-model
8.1kDạy agent của bạn xây dựng form trong Webiny bằng trình tạo trường khai báo, bố cục, kiểm tra hợp lệ và quy tắc có điều kiện.
Skill tương tự
api-connector-builder
280kGiúp agent của bạn xây dựng kết nối API mới theo đúng mẫu đã có, dùng khi bạn cần thêm một tích hợp mà không tạo cách làm mới.
api-design
280kGiúp agent của bạn thiết kế REST API theo các thực hành tốt nhất, hữu ích để định nghĩa cách API giao tiếp, hiển thị lỗi và tổ chức dữ liệu.
backend-patterns
280kGiúp agent của bạn với các mẫu kiến trúc phía máy chủ và tối ưu cơ sở dữ liệu, hữu ích khi xây dựng hoặc rà soát code chạy trên máy chủ.