Saltar al contenido principal

Obtener una página por ID

Obtiene una sola página por su ID numérico.

Qué hace este ejemplo:

  • Se conecta a la API de OneEntry
  • Obtiene una página por su ID numérico
  • Accede al contenido de la página mediante localizeInfos y attributeValues

Requisitos previos:

  • Un PROJECT_URL y un APP_TOKEN válidos para la API de OneEntry.
  • Una página configurada en OneEntry con un ID numérico conocido (p. ej., 9)

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.

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 la página por ID con Pages.getPageById()​

const page = await Pages.getPageById(9, 'en_US');

if ('statusCode' in page) {
throw new Error(page.message);
}

console.log(page.localizeInfos.title, page.attributeValues);
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
}

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 page by ID with Pages.getPageById()
const page = await Pages.getPageById(9, 'en_US');

if ('statusCode' in page) {
throw new Error(page.message);
}

console.log(page.localizeInfos.title, page.attributeValues);