Skip to main content

Call the nodes.getChildren() method in our delivery client to get the child nodes of an existing node from site view, optionally resolving an attached entry

Call signatures

TypeScript
getChildren(id: string): Promise<Node[]>

getChildren(node: Node): Promise<Node[]>

getChildren(options: NodeGetChildrenOptions): Promise<Node[]>

Parameters

NameTypeDescription
idstringThe id of the node
nodeNodeA node object
optionsNodeGetChildrenOptionsAn options object to apply additional refinements

Returns

A Promise that will resolve an array of Node

Remarks

Returns an empty array if no nodes exist with the specified entry

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

Example

Get the child nodes of an existing node

TypeScript
const children = await client.nodes.getChildren(
  "7a301bf2-96c3-461c-8068-bebe6783ecc5"
);

for (const node of children) {
  console.log(node.path);
}

Get the child nodes of an existing node also resolving the entryTitle field of any entry attached to the returned nodes

TypeScript
const children = await client.nodes.getChildren({
  id: "7a301bf2-96c3-461c-8068-bebe6783ecc5",
  entryFields: ["entryTitle"],
});

for (const node of children) {
  console.log(`${node.path} ${node.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