The Hierarchy API
Release date: 6th November 2024
Hierarchies can be used to model anything from a page structure for a website to a structured list of product content. This release features a new Hierarchy API that makes hierarchies easier and more efficient for developers to work with.
The Hierarchy API is a new Content Delivery API that allows developers to do the following:
- Get all the nodes at all levels of a hierarchy.
- Easily retrieve descendants of a specified node in a part of a hierarchy. This could be a product category such as "Electricals" or "Homeware" in a page hierarchy, or a section of a site map.
Using the Hierarchy APILink copied!
Given the ID of a hierarchy node, this API will return the descendants to the level specified.
Specify the hub name and the content item id of the parent node whose descendants will be returned. The optional hierarchyDepth
parameter allows you to choose how many levels deep to traverse the hierarchy. If you don't specify hierarchyDepth
then only the immediate descendants of the specified node will be returned (a depth of 1).
The API uses a pre-sort algorithm, starting with the first child node of a parent, retrieving all of its descendants, and then retrieving the descendants of each of its sibling nodes in turn.
You can also sort the content items in the API response using your own predefined sort key.
See the Hierarchy API page for more detail and examples.
ExampleLink copied!
The image below shows a hierarchy created from our page hierarchy schema example. The parent node is "Ideas and advice", a content item with the id 4c67ca5a-6050-490a-9859-be20e81ac89d
.
The entire hierarchy has a depth of 3 levels. To retrieve all descendants of the 'Ideas and advice' node, we specify the following hierarchy API request, with a hierarchy depth of 3.
You can see the response to this request by expanding the section below. The response is returned in the default sort order, returning "Heating and plumbing", "Lighting and electrical" and all its descendants, "Outdoor and garden" and all its descendants and then "Painting and decorating". You can also use define your own sort key to sort the response.
Example response
Retrieving uncached contentLink copied!
If you're building a static site, you can also use the updated Fresh API to retrieve all descendants of a hierarchy node with no cache.