Skillpedia
واجهات API والخوادم (backend)8.1k · #12617

webiny-sdk

ما الذي تفعله

يُظهر كيفية ربط تطبيق خارجي بنظام المحتوى Headless في Webiny لجلب المحتوى وإنشائه وتحديثه ونشره. وهي لمطورين يبنون مواقع أو تطبيقات تأخذ محتواها من Webiny.

متى تستخدمها

  • ✓عندما يبني مطور تطبيق Next.js أو Vue أو Node.js يحتاج إلى محتوى من Webiny.
  • ✓عندما يريد مطور نشر إدخال محتوى في Webiny أو إلغاء نشره من الكود.
  • ✓عندما يحتاج مطور إلى تصفية المحتوى أو ترتيبه أو تقسيمه إلى صفحات في تطبيق خارجي.

رابط المهارة

https://github.com/webiny/webiny-js/blob/next/skills/user-skills/webiny-sdk/SKILL.md

انسخه والصقه في الذكاء الاصطناعي الذي تستخدمه (Claude أو ChatGPT أو Cursor) واطلب منه اتباع التعليمات.

طريقة الاستخدام

أسهل طريقة: انسخ الرسالة والصقها في الذكاء الاصطناعي الذي تستخدمه. سيقرأ المهارة وينفّذ تعليماتها.

رسالة جاهزة للصق

استخدم هذه المهارة لمساعدتي: https://github.com/webiny/webiny-js/blob/next/skills/user-skills/webiny-sdk/SKILL.md اقرأ ملف SKILL.md في هذا الرابط ونفّذ تعليماته لمهمتي.
تريد أن يجد الذكاء الاصطناعي مهارات مثل هذه بنفسه؟ثبّت خادم Skillpedia MCP المجاني: سطر واحد، ويبحث في 15,000+ مهارة قبل كل مهمة.ثبّته في دقيقة واحدة →

مثال على ما تطلبه من الذكاء الاصطناعي

“كيف أجلب مقالات مدونتي من Webiny إلى موقع Next.js الخاص بي؟”

5 مهارات جديدة كل أسبوع. قراءة في دقيقة واحدة.

كيف تعمل

تُظهر المهارة كيفية إعداد 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. Run yarn webiny info in your Webiny project to find the API URL. For Website Builder projects use NEXT_PUBLIC_WEBSITE_BUILDER_API_HOST.
  • tenant -- Tenant ID, defaults to "root"

IMPORTANT: Never add a trailing slash to endpoint. The SDK appends /graphql to the endpoint internally, so https://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. وتقول المهارة إن نقطة النهاية تُعرف بتشغيل أمر المعلومات في مشروعك.

لماذا أحتاج إلى سرد الحقول في كل استدعاء؟

كل دالة في 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
الترخيص
—
آخر تحديث
2‏/11‏/2026

هل هذه المهارة مفيدة؟

0

سجّل الدخول للتصويت.

التعليقات

  • …

المزيد من المهارات من هذا المستودع

مهارات مشابهة