Obter página por ID
Neste exemplo, demonstramos como recuperar uma única página do CMS pelo seu ID numérico usando a API OneEntry.
✅ Propósito do cenário:
- Conectar-se à API OneEntry
- Recuperar uma página pelo seu ID numérico
- Acessar o conteúdo da página através de localizeInfos e attributeValues
✅ O que você precisa:
- Um PROJECT_URL e APP_TOKEN válidos para autenticação com a API OneEntry.
- Uma página configurada no OneEntry com um ID numérico conhecido (por exemplo, 9)
📌 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).
📚 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 página por ID — Neste exemplo, demonstramos como recuperar uma única página do CMS pelo seu ID numérico 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 página por ID com Pages.getPageById()
Exemplo:
const page = await Pages.getPageById(9, 'en_US');
console.log('Page: ', page);
Resultado:
{
"id": 9,
"parentId": null,
"pageUrl": "home_web",
"depth": 0,
"localizeInfos": {
"title": "Home web",
"menuTitle": "Home web",
"htmlContent": "",
"plainContent": ""
},
"isVisible": true,
"blocks": [],
"type": "common_page",
"templateIdentifier": null,
"attributeSetIdentifier": null,
"attributeValues": {},
"moduleFormConfigs": [],
"isSync": false
}
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 page by ID with [Pages.getPageById()](/docs/pages/getPageById)
const page = await Pages.getPageById(9, 'en_US');
console.log('Page: ', page);