Skip to main content

Get page by ID

Fetches a single page by its numeric ID.

What this example does:

  • Connects to the OneEntry API
  • Retrieves a page by its numeric ID
  • Accesses page content via localizeInfos and attributeValues

Prerequisites:

  • A valid PROJECT_URL and APP_TOKEN for the OneEntry API.
  • A page configured in OneEntry with a known numeric ID (e.g., 9)

Notes:

  • By default (isShell: true) the SDK returns an error object instead of throwing, so check the result, e.g. 'statusCode' in result. With isShell: false it throws, and you handle errors with try/catch. See Errors.

Platform docs:

SDK reference:

Try it live​

Run this example in the JS SDK sandbox. Connect your Project URL and App Token on first visit, then open:

Scenario​

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);
Result:
{
"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
}

Final example​

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