Skip to main content

Call the nodes.getRoot() method in our delivery client to return the root node from the project site view tree

Call signatures

TypeScript
getRoot(options?: NodeGetRootOptions): Promise<Node>

Parameters

NameTypeDescription
optionsNodeGetRootOptionsAn options object to apply additional refinements

Returns

A Promise that will resolve with the root Node

Remarks

Throws any error that is returned by the API for any unsuccessful request echoing the HTTP status returned from the API

Example

Get the root node with default options

TypeScript
const node = await client.nodes.getRoot();

console.log(node);

Get root node for a specific language while resolving children to a depth of 1 and the entry title field from any entry attached to any resolved node

TypeScript
const node = await client.nodes.getRoot({
  depth: 1,
  language: "en-GB",
  entryFields: ["entryTitle"],
});

for (const child of node.children) {
  console.log(
    child.path,
    child.childCount ? `+${child.childCount}` : "",
    child.entry?.entryTitle || ""
  );
}

Still need help?

If you still need help after reading this article, don't hesitate to reach out to the Contensis community on Slack or raise a support ticket to get help from our team.
New support request