Saltar al contenido principal

Obtener todas las páginas

Obtiene todas las páginas del proyecto, no solo las raíz.

Qué hace este ejemplo:

  • Se conecta a la API de OneEntry
  • Obtiene todas las páginas de todos los niveles de profundidad en una sola llamada
  • Filtra las páginas por tipo mediante el campo type

Requisitos previos:

  • Un PROJECT_URL y un APP_TOKEN válidos para la API de OneEntry.
  • Al menos una página configurada en OneEntry.

Notas:

  • Por defecto (isShell: true), el SDK devuelve un objeto de error en lugar de lanzar una excepción, así que comprueba el resultado, p. ej., 'statusCode' in result. Con isShell: false lanza la excepción y los errores se manejan con try/catch. Consulta Errors.
  • Devuelve un array simple, no { items, total }. Incluye páginas de todas las profundidades; usa el campo depth o parentId para construir un árbol.
  • El campo type es "common_page" para páginas de contenido, "catalog_page" para páginas con productos, "error_page" para páginas de error o "external_page" para enlaces a URL externas.
  • El campo products de cada objeto de página indica el número de productos asignados a esa página.

Documentación de la plataforma:

Referencia del SDK:

Pruébalo en vivo​

Ejecuta este ejemplo en el sandbox del SDK de JS. Conecta tu Project URL y App Token en la primera visita y luego abre:

Escenario​

1. Importar defineOneEntry y definir PROJECT_URL y APP_TOKEN​

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';

2. Crear un cliente de API con defineOneEntry()​

const { Pages } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});

3. Obtener todas las páginas con 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);
}
Resultado:
[
{
"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. Filtrar las páginas y acceder a sus campos​

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);
});
Resultado (valores de una página):
{
"title": "Services",
"type": "catalog_page",
"pageUrl": "services",
"depth": 0,
"parentId": null
}

Ejemplo final​

// 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);
});