Pular para o conteúdo principal

Obter uma página pela URL

Busca uma única página pelo identificador de URL.

O que este exemplo faz:

  • Conecta-se à API do OneEntry
  • Recupera uma página pelo seu identificador de URL
  • Acessa o conteúdo da página por meio de localizeInfos e attributeValues

Pré-requisitos:

  • Um PROJECT_URL e um APP_TOKEN válidos para a API do OneEntry.
  • Uma página configurada no OneEntry com uma URL conhecida (ex.: "home_web")

Observações:

  • Por padrão (isShell: true), o SDK retorna um objeto de erro em vez de lançar uma exceção, então verifique o resultado, por exemplo 'statusCode' in result. Com isShell: false, ele lança a exceção, e você trata os erros com try/catch. Veja Erros.

Documentação da plataforma:

Referência do SDK:

Experimente ao vivo​

Execute este exemplo no sandbox do JS SDK. Conecte a URL do seu projeto e o App Token na primeira visita e, em seguida, abra:

Cenário​

1. Importar defineOneEntry e definir PROJECT_URL e APP_TOKEN​

import { defineOneEntry } from 'oneentry';

const PROJECT_URL = 'https://your-project.oneentry.cloud';
const APP_TOKEN = 'your-app-token';

2. Criar um cliente da API com defineOneEntry()​

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

3. Obter a página pela URL com Pages.getPageByUrl()​

const page = await Pages.getPageByUrl('home_web');

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
}

Exemplo 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 URL with Pages.getPageByUrl()
const page = await Pages.getPageByUrl('home_web');

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

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