Skip to main content

Get root

Gets the root node of the tree.

Parameters

options

Type: NodeGetRootOptions
The options for requesting a root node. If the argument is not provided then the default option will be used.

Examples

JavaScript
// get root node with default options
ContensisClient.nodes.getRoot().then(function(node) {
    // root node is available
}, function(error) {
    console.error(error);
});

// get root node with specific options
ContensisClient.nodes.getRoot({ 
        language: 'fr-FR', 
        fields: ['title'], 
        depth: 2 
    }).then(function(node) {
    // root node is available
}, function(error) {
    console.error(error);
});

Get node

Gets a node by id or path.

Parameters

The idOrPathOrOptions parameter can be one of the following types.

idOrPathOrOptions

Type: string
The node id or the node path.

idOrPathOrOptions

Type: NodeGetByIdOptions
The options for requesting a node by id.

idOrPathOrOptions

Type: NodeGetByPathOptions
The options for requesting a node by path.

Remarks

Returns null if a node with the specified id or path does not exist.

Examples

JavaScript
// get node by id
ContensisClient.nodes.get('57d77dbc-49da-40ca-aaaf-3b877b69699a').then(function(node) {
    // the node is available
}, function(error) {
    console.error(error);
});

 // get node by path
ContensisClient.nodes.get('/en-GB/movies/1995/toy-story').then(function(node) {
    // the node is available
}, function(error) {
    console.error(error);
});

// get node by id with specific options
ContensisClient.nodes.get({ 
        id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
        language: 'fr-FR', 
        fields: ['title'], 
        depth: 2 
    }).then(function(node) {
    // the node is available
}, function(error) {
    console.error(error);
});

 // get node by path with specific options
ContensisClient.nodes.get({ 
        path: '/en-GB/movies/1995/toy-story',
        language: 'fr-FR', 
        fields: ['title'], 
        depth: 2 
    }).then(function(node) {
    // the node is available
}, function(error) {
    console.error(error);
});

Get nodes by entry

Gets an array of nodes assigned to an entry.

Parameters

The entryIdOrEntryOrOptions parameter can be one of the following types.

entryIdOrEntryOrOptions

Type: string
The entry id.

entryIdOrEntryOrOptions

Type: Entry
The entry.

entryIdOrEntryOrOptions

Type: NodeGetByEntryOptions
The options for requesting nodes assigned to an entry.

Examples

JavaScript
// get node by entry id
ContensisClient.nodes.getByEntry('ba950397-5e7c-4847-a07f-cf015b9e59cb').then(function(node) {
    // the node is available
}, function(error) {
    console.error(error);
});

// get node by entry
const entry = {
    'title' : 'An entry',
    sys: {
        id: 'ba950397-5e7c-4847-a07f-cf015b9e59cb',
        contentTypeId: 'movie'
    }
};     
ContensisClient.nodes.getByEntry(entry).then(function(node) {
    // the node is available
}, function(error) {
    console.error(error);
});

// get node by entry with specific options using the entry id
ContensisClient.nodes.getByEntry({ 
        entryId: 'ba950397-5e7c-4847-a07f-cf015b9e59cb',
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(node) {
    // the node is available
}, function(error) {
    console.error(error);
});

    // get node by entry with specific options using the entry
ContensisClient.nodes.getByEntry({ 
        entry: entry,
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(node) {
    // the node is available
}, function(error) {
    console.error(error);
});

Get node children

Gets node children.

Parameters

The idOrNodeOrOptions parameter can be one of the following types.

idOrNodeOrOptions

Type: string
The node id.

idOrNodeOrOptions

Type: Node
The node.

idOrNodeOrOptions

Type: NodeGetChildrenOptions
The options for requesting node children.

Examples

JavaScript
// get node children by node id
ContensisClient.nodes.getChildren('57d77dbc-49da-40ca-aaaf-3b877b69699a').then(function(nodes) {
    // the node children are available
}, function(error) {
    console.error(error);
});

// get node children by node
const node = {
    id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
    title: 'Toy Story',
    path: '/en-GB/movies/1995/toy-story'    
};     
ContensisClient.nodes.getChildren(node).then(function(nodes) {
    // the node children are available
}, function(error) {
    console.error(error);
});

// get node children with specific options using the node id
ContensisClient.nodes.getChildren({ 
        id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(nodes) {
    // the node children are available
}, function(error) {
    console.error(error);
});

    // get node children with specific options using the node
ContensisClient.nodes.getChildren({ 
        node: node,
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(nodes) {
    // the node children are available
}, function(error) {
    console.error(error);
});

Get node parent

Gets a node parent.

Parameters

The idOrNodeOrOptions parameter can be one of the following types.

idOrNodeOrOptions

Type: string
The node id.

idOrNodeOrOptions

Type: Node
The node.

idOrNodeOrOptions

Type: NodeGetParentOptions
The options for requesting a node parent.

Examples

JavaScript

// get node parent by node id
ContensisClient.nodes.getParent('57d77dbc-49da-40ca-aaaf-3b877b69699a').then(function(parentNode) {
    // the node parent is available
}, function(error) {
    console.error(error);
});

// get node parent by node
const node = {
    id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
    title: 'Toy Story',
    path: '/en-GB/movies/1995/toy-story'    
};     
ContensisClient.nodes.getParent(node).then(function(parentNode) {
    // the node parent is available
}, function(error) {
    console.error(error);
});

// get node parent with specific options using the node id
ContensisClient.nodes.getParent({ 
        id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(parentNode) {
    // the node parent is available
}, function(error) {
    console.error(error);
});

    // get node parent with specific options using the node
ContensisClient.nodes.getParent({ 
        node: node,
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(parentNode) {
    // the node parent is available
}, function(error) {
    console.error(error);
});

Get node ancestor at level

Gets a node ancestor at a specified level.

Parameters

options

Type: NodeGetAncestorAtLevelOptions
The options for requesting a node ancestor at a specified level.

Remarks

If a level is specified that is equal to or greater than the level of the start node then null will be returned.

Examples

JavaScript
// get node ancestor  with specific options using the node id
ContensisClient.nodes.getAncestorAtLevel({ 
        id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
        startLevel: 1,
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(ancestorNode) {
    // the node ancestor is available
}, function(error) {
    console.error(error);
});

    // get node ancestor with specific options using the node
const node = {
    id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
    title: 'Toy Story',
    path: '/en-GB/movies/1995/toy-story'    
};        
ContensisClient.nodes.getAncestorAtLevel({ 
        node: node,
        startLevel: 1,
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(ancestorNode) {
    // the node ancestor is available
}, function(error) {
    console.error(error);
});

Get node ancestors

Gets node ancestors.

Parameters

The idOrNodeOrOptions parameter can be one of the following types.

idOrNodeOrOptions

Type: string
The node id.

idOrNodeOrOptions

Type: Node
The node.

idOrNodeOrOptions

Type: NodeGetAncestorsOptions
The options for requesting node ancestors.

Remarks

If a level is specified that is equal to or greater than the level of the start node then an empty array will be returned.

Examples

JavaScript
// get node ancestors by node id
ContensisClient.nodes.getAncestors('57d77dbc-49da-40ca-aaaf-3b877b69699a').then(function(nodes) {
    // the node ancestors are available
}, function(error) {
    console.error(error);
});

// get node ancestors by node
const node = {
    id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
    title: 'Toy Story',
    path: '/en-GB/movies/1995/toy-story'    
};     
ContensisClient.nodes.getAncestors(node).then(function(nodes) {
    // the node ancestors are available
}, function(error) {
    console.error(error);
});

// get node ancestors with specific options using the node id
ContensisClient.nodes.getAncestors({ 
        id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
        language: 'fr-FR', 
        startLevel: 1,
        fields: ['description']
    }).then(function(nodes) {
    // the node ancestors are available
}, function(error) {
    console.error(error);
});

    // get node ancestors with specific options using the node
ContensisClient.nodes.getAncestors({ 
        node: node,
        startLevel: 1,
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(nodes) {
    // the node ancestors are available
}, function(error) {
    console.error(error);
});

Get node siblings

Gets node siblings.

Parameters

The idOrNodeOrOptions parameter can be one of the following types.

idOrNodeOrOptions

Type: string
The node id.

idOrNodeOrOptions

Type: Node
The node.

idOrNodeOrOptions

Type: NodeGetSiblingsOptions
The options for requesting node siblings.

Examples

JavaScript
// get node siblings by node id
ContensisClient.nodes.getSiblings('57d77dbc-49da-40ca-aaaf-3b877b69699a').then(function(nodes) {
    // the node siblings are available
}, function(error) {
    console.error(error);
});

// get node siblings by node
const node = {
    id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
    title: 'Toy Story',
    path: '/en-GB/movies/1995/toy-story'    
};     
ContensisClient.nodes.getSiblings(node).then(function(nodes) {
    // the node siblings are available
}, function(error) {
    console.error(error);
});

// get node siblings with specific options using the node id
ContensisClient.nodes.getSiblings({ 
        id: '57d77dbc-49da-40ca-aaaf-3b877b69699a',
        language: 'fr-FR',             
        fields: ['description']
    }).then(function(nodes) {
    // the node siblings are available
}, function(error) {
    console.error(error);
});

    // get node siblings with specific options using the node
ContensisClient.nodes.getSiblings({ 
        node: node,            
        language: 'fr-FR', 
        fields: ['description']
    }).then(function(nodes) {
    // the node siblings are available
}, function(error) {
    console.error(error);
});

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