Obter todas as páginas
Neste exemplo, demonstramos como recuperar todas as páginas do projeto CMS (não apenas as de nível raiz) usando a API OneEntry.
✅ Propósito do cenário:
- Conectar-se à API OneEntry
- Recuperar todas as páginas em todos os níveis de profundidade em uma única chamada
- Filtrar páginas por tipo usando o campo tipo
✅ O que você precisa:
- Um PROJECT_URL e APP_TOKEN válidos para autenticação com a API OneEntry.
- Pelo menos uma página configurada no OneEntry.
📌 Importante:
- Estes exemplos não incluem tratamento de erros.
- Você pode gerenciar erros usando um bloco try-catch ou empregando uma construção como await Promise.catch((error) => error).
- Retorna um array simples, NÃO
{ items, total }. Inclui páginas de todas as profundidades — use o campo depth ou parentId para construir uma árvore. - O campo tipo é "common_page" para páginas de conteúdo e "catalog_page" para páginas com produtos.
- O campo products em cada objeto de página mostra a contagem de produtos atribuídos a essa página.
📚 Veja na documentação:
📦 Referência do SDK:
Experimente ao vivo
Execute este método interativamente no sandbox do JS SDK — conecte seu Project URL e App Token na primeira visita, depois abra:
- Obter todas as páginas — Neste exemplo, demonstramos como recuperar todas as páginas do projeto CMS (não apenas as de nível raiz) usando a API OneEntry.
Cenário
1. Importar defineOneEntry do SDK e definir PROJECT_URL e APP_TOKEN
Exemplo:
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
2. Criando um cliente API com defineOneEntry()
Exemplo:
const { Pages } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
3. Obter todas as páginas com Pages.getPages()
Exemplo:
// 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": 49,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "products",
"attributeSetIdentifier": null,
"total": "9",
"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,
"total": "9",
"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,
"total": "9",
"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,
"total": "9",
"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,
"total": "9",
"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,
"total": "9",
"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,
"total": "9",
"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,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {},
"nestedEntityIdentifiers": [],
"exceptionIds": []
}
]
},
{
"id": 11,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "schedule",
"attributeSetIdentifier": null,
"total": "9",
"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,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"schedule": 1
},
"nestedEntityIdentifiers": [],
"exceptionIds": []
}
]
},
{
"id": 2,
"config": {},
"depth": 0,
"parentId": null,
"pageUrl": "services",
"attributeSetIdentifier": null,
"total": "9",
"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,
"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,
"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,
"maxRatingScale": null,
"isAnonymous": null,
"allowRerating": null,
"isRating": null,
"entityFormDataCount": {
"services": 31
},
"nestedEntityIdentifiers": [],
"exceptionIds": []
}
]
}
]
4. Filtrar e acessar campos da página
Exemplo:
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"
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:
{
"title": "Services",
"type": "catalog_page",
"pageUrl": "services",
"depth": 0,
"parentId": null
}
Exemplo final
// 1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN
import { defineOneEntry } from 'oneentry';
const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';
// 2. Creating an API client with [defineOneEntry()](/docs/index/#Installation)
const { Pages } = defineOneEntry(PROJECT_URL, {
token: APP_TOKEN,
});
// 3. Get all pages with [Pages.getPages()](/docs/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"
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);
});