Skip to main content

Get page by ID

In this example, we demonstrate how to retrieve a single CMS page by its numeric ID using the OneEntry API.

✅ Purpose of the scenario:

  • Connect to the OneEntry API
  • Retrieve a page by its numeric ID
  • Access page content via localizeInfos and attributeValues

✅ What you need:

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

📌 Important:

  • These examples do not include error handling.
  • You can manage errors using a try-catch block or by employing a construction like await Promise.catch((error) => error).

📚 See in documentation:

📦 SDK reference:

Try it live

Run this method interactively in the JS SDK sandbox — connect your Project URL and App Token on first visit, then open:

  • Get page by ID — In this example, we demonstrate how to retrieve a single CMS page by its numeric ID using the OneEntry API.

Scenario

1. Import defineOneEntry from SDK and define PROJECT_URL and APP_TOKEN

Example:

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'your-project-url';
const APP_TOKEN = 'your-app-token';

2. Creating an API client with defineOneEntry()

Example:

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

3. Get page by ID with Pages.getPageById()

Example:

const page = await Pages.getPageById(9, 'en_US');
console.log('Page: ', page);
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 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);