Retrieving hierarchical content
On this page we provide an overview of how to retrieve content items from a hierarchy. You can find more information and examples on the Hierarchy API and Filter API pages.
When to use the Hierarchy API and Filter APILink copied!
Both the Hierarchy API and Filter API have their advantages:
The Filter API can be used to retrieve only the immediate children of a hierarchy node. However, you can filter by the parent node and the value of a property.
The Hierarchy API can be used to retrieve all nodes in a hierarchy, or parts of a hierarchy, up to a maximum depth of 14 levels.
The Filter API can be used to retrieve linked content, the Hierarchy API does not currently return linked content.
Hierarchy API requests have a larger page size, 100 items compared to a maximum of 50 for the Filter API.
The Hierarchy API is better suited to use cases where large hierarchies are being returned with minimal linked content, while the Filter API is better suited to use cases with a lot of linked content.
Using hierarchies with the Content Delivery APILink copied!
When you publish a hierarchy node you can choose whether to publish it on its own or together with its dependents. The Content Delivery API includes some additional information about a node under the hierarchy
element. Here's an example of the content returned for the root of the hierarchy- that is the node that has no parent item. You can see that root
is set to true.
Here's the content returned for an item named "Clearance", you will notice that this includes a parentId
element. This is the node's immediate parent, in this case the root node shown above. You can use the parentId
to traverse back up the tree or with the Filter API to find the immediate children of the parent.
Use the Hierarchy API to find all descendants of the specified node, which can be the entire hierarchy or just a part of it.
Retrieving all descendants of a hierarchy nodeLink copied!
The Hierarchy API allows you to retrieve all descendants of a specified node in a hierarchy. The following example shows how to retrieve all descendants of the node with the content item id 4c67ca5a-6050-490a-9859-be20e81ac89d
to a depth of 3 levels.
You can see the response to this request by expanding the section below.
Example response from the Hierarchy API
Listing immediate children of a hierarchy nodeLink copied!
Using the Filter API you can list all the children of a specified parent node by setting the filter path to /_meta/hierarchy/parentId
,as shown in the content returned from the Delivery API, and setting the parent id to the deliveryId
of the item whose children you want to return. You can use the Hierarchy API to return all children in all levels of a hierarchy.
In the example filter API request shown below we are requesting all the children of the hierarchy node with the id "b158fe6b-fe4b-46e3-92c5-33f8a4e5675c". Note that just the immediate children will be returned.
Try it outLink copied!
To try out the filter request use the following cURL.
An example response is shown below. These are the items that have the node with the id "b158fe6b-fe4b-46e3-92c5-33f8a4e5675c" as their parent.