الحصول على جميع الصفحات
يجلب جميع صفحات المشروع، وليس الصفحات الجذرية فقط.
ما يفعله هذا المثال:
- يتصل بـ OneEntry API
- يسترجع جميع الصفحات عبر جميع مستويات العمق في استدعاء واحد
- يفلتر الصفحات حسب النوع باستخدام الحقل type
المتطلبات المسبقة:
- قيمتا PROJECT_URL وAPP_TOKEN صالحتان لـ OneEntry API.
- صفحة واحدة على الأقل مهيأة في OneEntry.
ملاحظات:
- افتراضيًا (
isShell: true) يُعيد SDK كائن خطأ بدلًا من رمي استثناء، لذا تحقق من النتيجة، مثل'statusCode' in result. معisShell: falseيرمي استثناءً، وتعالج الأخطاء باستخدام try/catch. راجع الأخطاء. - تُعيد مصفوفة عادية، وليس
{ items, total }. تتضمن صفحات بجميع الأعماق؛ استخدم الحقل depth أو parentId لبناء شجرة. - قيمة حقل type هي "common_page" لصفحات المحتوى، و"catalog_page" للصفحات التي تحتوي على منتجات، و"error_page" لصفحات الأخطاء، و"external_page" للروابط إلى عناوين URL خارجية.
- يُظهر الحقل products في كل كائن صفحة عدد المنتجات المعيّنة لتلك الصفحة.
وثائق المنصة:
مرجع SDK:
جربها مباشرة
شغّل هذا المثال في بيئة JS SDK التجريبية. اربط Project URL وApp Token عند الزيارة الأولى، ثم افتح:
السيناريو
1. استورد defineOneEntry وعرّف PROJECT_URL وAPP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';
2. أنشئ عميل API باستخدام defineOneEntry()
const { Pages } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. احصل على جميع الصفحات باستخدام Pages.getPages()
// Returns a plain array (NOT `{ items, total }`)
const pages = await Pages.getPages('en_US');
if ('statusCode' in pages) {
throw new Error(pages.message);
}
النتيجة:
[
{
"id": 9,
"config": {},
"depth": 1,
"parentId": 8,
"pageUrl": "blog1",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Blog 1",
"htmlContent": "",
"plainContent": "",
"menuTitle": "Blog 1"
},
"isVisible": true,
"products": 0,
"childrenCount": 0,
"type": "common_page",
"position": 2,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "blog/blog1",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": []
},
{
"id": 8,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "blog",
"attributeSetIdentifier": "page",
"localizeInfos": {
"title": "Blog",
"htmlContent": "",
"plainContent": "",
"menuTitle": "Blog"
},
"isVisible": true,
"products": 0,
"childrenCount": 2,
"type": "common_page",
"position": 3,
"templateIdentifier": "template",
"isSync": true,
"categoryPath": "blog",
"rating": {},
"attributeValues": {
"text": {
"type": "string",
"value": "some text",
"isIcon": false,
"position": 0,
"additionalFields": {},
"isProductPreview": false
},
"number": {
"type": "integer",
"value": 5,
"isIcon": false,
"position": 1,
"additionalFields": {},
"isProductPreview": false
},
"real": {
"type": "real",
"value": 10,
"isIcon": false,
"position": 2,
"additionalFields": {},
"isProductPreview": false
},
"float": {
"type": "float",
"value": 12,
"isIcon": false,
"position": 3,
"additionalFields": {},
"isProductPreview": false
}
},
"moduleFormConfigs": [
{
"id": 9,
"formIdentifier": "full_form",
"moduleIdentifier": "content",
"isGlobal": false,
"isClosed": false,
"isModerate": true,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "blog",
"isNested": false
}
],
"formDataCount": 6281,
"ratingCalculation": "average",
"allowHalfRatings": null,
"showAggregatedRating": null,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"blog": 6281
},
"nestedEntityIdentifiers": [],
"exceptionIds": []
},
{
"id": 3,
"formIdentifier": "file_form",
"moduleIdentifier": "content",
"isGlobal": false,
"isClosed": false,
"isModerate": false,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "blog",
"isNested": false
}
],
"formDataCount": 691,
"ratingCalculation": "average",
"allowHalfRatings": null,
"showAggregatedRating": null,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"blog": 691
},
"nestedEntityIdentifiers": [],
"exceptionIds": []
},
{
"id": 2,
"formIdentifier": "test-form",
"moduleIdentifier": "content",
"isGlobal": false,
"isClosed": false,
"isModerate": false,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "blog",
"isNested": false
}
],
"formDataCount": 909,
"ratingCalculation": "average",
"allowHalfRatings": null,
"showAggregatedRating": null,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"blog": 909
},
"nestedEntityIdentifiers": [],
"exceptionIds": []
}
],
"template": {
"id": 4,
"attributeSetIdentifier": null,
"title": "Template",
"generalTypeId": 4,
"identifier": "template",
"version": 0,
"generalTypeName": "catalog_page",
"attributeValues": {},
"position": 1
}
},
{
"id": 49,
"config": {},
"depth": 1,
"parentId": 8,
"pageUrl": "blog2",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Blog 2",
"htmlContent": "",
"plainContent": "",
"menuTitle": "Blog 2"
},
"isVisible": true,
"products": 0,
"childrenCount": 0,
"type": "common_page",
"position": 1,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "blog2",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": []
}
]
4. صفِّ حقول الصفحة وصل إليها
const catalogPages = pages.filter((p: { type: string }) => p.type === 'catalog_page');
console.log('catalogPages ', catalogPages);
const commonPages = pages.filter((p: { type: string }) => p.type === 'common_page');
console.log('commonPages ', commonPages);
pages.forEach((page) => {
const title = page.localizeInfos?.title;
const type = page.type; // "common_page" | "catalog_page" | "error_page" | "external_page"
const pageUrl = page.pageUrl;
const depth = page.depth; // 0 for root, 1+ for children
const parentId = page.parentId; // null for root pages
console.log(title, type, pageUrl, depth, parentId);
});
النتيجة (القيم لصفحة واحدة):
{
"title": "Services",
"type": "catalog_page",
"pageUrl": "services",
"depth": 0,
"parentId": null
}
المثال النهائي
// 1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';
// 2. Create an API client with defineOneEntry()
const { Pages } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. Get all pages with Pages.getPages()
// Returns a plain array (NOT `{ items, total }`)
const pages = await Pages.getPages('en_US');
if ('statusCode' in pages) {
throw new Error(pages.message);
}
// 4. Filter and access page fields
const catalogPages = pages.filter((p: { type: string }) => p.type === 'catalog_page');
console.log('catalogPages ', catalogPages);
const commonPages = pages.filter((p: { type: string }) => p.type === 'common_page');
console.log('commonPages ', commonPages);
pages.forEach((page) => {
const title = page.localizeInfos?.title;
const type = page.type; // "common_page" | "catalog_page" | "error_page" | "external_page"
const pageUrl = page.pageUrl;
const depth = page.depth; // 0 for root, 1+ for children
const parentId = page.parentId; // null for root pages
console.log(title, type, pageUrl, depth, parentId);
});