انتقل إلى المحتوى الرئيسي

الحصول على الصفحات الجذرية

يجلب جميع الصفحات من المستوى الأعلى (الجذرية).

ما يفعله هذا المثال:

  • يتصل بـ OneEntry API
  • يسترجع جميع صفحات المستوى الجذري في استدعاء واحد
  • يصل إلى بيانات الصفحة الوصفية مثل النوع والعنوان وعدد المنتجات

المتطلبات المسبقة:

  • قيمتا PROJECT_URL وAPP_TOKEN صالحتان لـ OneEntry API.
  • صفحة جذرية واحدة على الأقل مهيأة في OneEntry.

ملاحظات:

  • افتراضيًا (isShell: true) يُعيد SDK كائن خطأ بدلًا من رمي استثناء، لذا تحقق من النتيجة، مثل 'statusCode' in result. مع isShell: false يرمي استثناءً، وتعالج الأخطاء باستخدام try/catch. راجع الأخطاء.
  • تُعيد getRootPages() مصفوفة عادية، وليس { items, total }.
  • قيمة حقل 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';
import type { IPagesEntity } 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.getRootPages()​

// Returns a plain array (NOT `{ items, total }`)
const pages = await Pages.getRootPages('en_US');

if ('statusCode' in pages) {
throw new Error(pages.message);
}
console.log('Pages: ', pages);
النتيجة:
[
{
"id": 49,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "products",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Products",
"menuTitle": "Products",
"htmlContent": "",
"plainContent": ""
},
"isVisible": true,
"products": 3,
"childrenCount": 0,
"type": "catalog_page",
"position": 9,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "products",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": []
},
{
"id": 35,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "get-all-pages",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Get all pages",
"mdContent": "",
"menuTitle": "Get all pages",
"htmlContent": "<p>In this example, we demonstrate how to retrieve all pages of all depths using the OneEntry API.</p>",
"plainContent": ""
},
"isVisible": true,
"products": 0,
"childrenCount": 0,
"type": "common_page",
"position": 8,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "get-all-pages",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": []
},
{
"id": 10,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "blocks",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Blocks",
"menuTitle": "Blocks",
"htmlContent": "",
"plainContent": ""
},
"isVisible": true,
"products": 0,
"childrenCount": 0,
"type": "common_page",
"position": 7,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "blocks",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": []
},
{
"id": 9,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "home_web",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Home web",
"menuTitle": "Home web",
"htmlContent": "",
"plainContent": ""
},
"isVisible": true,
"products": 0,
"childrenCount": 0,
"type": "common_page",
"position": 6,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "home_web",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": []
},
{
"id": 7,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "premium_page",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Premium page",
"menuTitle": "Premium page",
"htmlContent": "",
"plainContent": ""
},
"isVisible": true,
"products": 0,
"childrenCount": 0,
"type": "common_page",
"position": 5,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "premium_page",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": []
},
{
"id": 6,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "subscriptions",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Subscriptions",
"menuTitle": "Subscriptions",
"htmlContent": "",
"plainContent": ""
},
"isVisible": true,
"products": 3,
"childrenCount": 0,
"type": "catalog_page",
"position": 4,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "subscriptions",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": []
},
{
"id": 8,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "tickets",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Tickets",
"menuTitle": "Tickets",
"htmlContent": "",
"plainContent": ""
},
"isVisible": true,
"products": 3,
"childrenCount": 0,
"type": "catalog_page",
"position": 3,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "tickets",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": [
{
"id": 5,
"formIdentifier": "spam_form",
"moduleIdentifier": "content",
"isGlobal": false,
"isClosed": false,
"isModerate": true,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "tickets",
"isNested": false
}
],
"formDataCount": 0,
"ratingCalculation": "average",
"allowHalfRatings": null,
"showAggregatedRating": null,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {},
"nestedEntityIdentifiers": [],
"exceptionIds": []
}
]
},
{
"id": 11,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "schedule",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Schedule form",
"mdContent": "",
"menuTitle": "Schedule form",
"htmlContent": "<p>In this example, we demonstrate how to get a form with a timeInterval field and submit a selected time slot using the OneEntry API.</p>",
"plainContent": ""
},
"isVisible": true,
"products": 0,
"childrenCount": 0,
"type": "common_page",
"position": 2,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "schedule",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": [
{
"id": 7,
"formIdentifier": "schedule",
"moduleIdentifier": "content",
"isGlobal": false,
"isClosed": false,
"isModerate": true,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "schedule",
"isNested": false
}
],
"formDataCount": 1,
"ratingCalculation": "average",
"allowHalfRatings": null,
"showAggregatedRating": null,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"schedule": 1
},
"nestedEntityIdentifiers": [],
"exceptionIds": []
}
]
},
{
"id": 2,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "services",
"attributeSetIdentifier": null,
"localizeInfos": {
"title": "Services",
"menuTitle": "Services",
"htmlContent": "",
"plainContent": ""
},
"isVisible": true,
"products": 3,
"childrenCount": 0,
"type": "catalog_page",
"position": 1,
"templateIdentifier": null,
"isSync": false,
"categoryPath": "services",
"rating": {},
"attributeValues": {},
"moduleFormConfigs": [
{
"id": 3,
"formIdentifier": "file",
"moduleIdentifier": "content",
"isGlobal": false,
"isClosed": false,
"isModerate": false,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "services",
"isNested": false
}
],
"formDataCount": 14,
"ratingCalculation": "average",
"allowHalfRatings": null,
"showAggregatedRating": null,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"services": 14
},
"nestedEntityIdentifiers": [],
"exceptionIds": []
},
{
"id": 2,
"formIdentifier": "contact_us",
"moduleIdentifier": "content",
"isGlobal": false,
"isClosed": false,
"isModerate": false,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "services",
"isNested": false
}
],
"formDataCount": 60,
"ratingCalculation": "average",
"allowHalfRatings": null,
"showAggregatedRating": null,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"services": 60
},
"nestedEntityIdentifiers": [],
"exceptionIds": []
},
{
"id": 1,
"formIdentifier": "entity",
"moduleIdentifier": "content",
"isGlobal": false,
"isClosed": false,
"isModerate": false,
"viewOnlyMyData": false,
"commentOnlyMyData": false,
"entityIdentifiers": [
{
"id": "services",
"isNested": false
}
],
"formDataCount": 31,
"ratingCalculation": "average",
"allowHalfRatings": null,
"showAggregatedRating": null,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"services": 31
},
"nestedEntityIdentifiers": [],
"exceptionIds": []
}
]
}
]

4. الوصول إلى حقول الصفحة​

pages.forEach((page: IPagesEntity) => {
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 pages
const childrenCount = page.childrenCount;
const productsCount = page.products; // number of products on this page
console.log(title, type, pageUrl, depth, childrenCount, productsCount);
});
النتيجة (القيم لصفحة واحدة):
{
"title": "Services",
"type": "catalog_page",
"pageUrl": "services",
"depth": 0,
"childrenCount": 0,
"productsCount": 3
}

المثال النهائي​

// 1. Import defineOneEntry and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
import type { IPagesEntity } 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 root pages with Pages.getRootPages()
// Returns a plain array (NOT `{ items, total }`)
const pages = await Pages.getRootPages('en_US');

if ('statusCode' in pages) {
throw new Error(pages.message);
}
console.log('Pages: ', pages);

// 4. Access page fields
pages.forEach((page: IPagesEntity) => {
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 pages
const childrenCount = page.childrenCount;
const productsCount = page.products; // number of products on this page
console.log(title, type, pageUrl, depth, childrenCount, productsCount);
});