Hierarchy API
The hierarchy API allows you to get all descendants of a hierarchy node. We have included an increased maximum page size for the API response so that you can retrieve an entire hierarchy with fewer requests.
The API is designed to make it easier to work with hierarchies used to model use cases such as the following examples:
- Getting all the nodes at all levels of a hierarchy used for a site map or to model store locations.
- 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.
If you are building a static site, you can retrieve all descendants of a hierarchy node using the Fresh API
Get all descendantsLink copied!
Given the ID or delivery key of a hierarchy node, this API will return the descendants to the level specified.
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.
Request URLLink copied!
Request method: GET
.
Specify the hub name and either the content item id or delivery key of the parent node whose descendants will be returned.
Content item idLink copied!
Delivery keyLink copied!
Note: The parent item will not be returned in the response.
ParametersLink copied!
The API accepts the following path parameters, all of which are optional.
Parameter | Description |
---|---|
hierarchyDepth | Returns descendants of the parent node to the specified depth. The maximum depth is 14, the default depth is 1. The parent node is level 0 |
sortByKey | The custom sort order. Note: Content is sorted by creation date if sort order is not specified. See Sorting for more details |
sortByOrder | The sort order for the items in the response. Ascending (asc) or descending (desc). Ascending order is used if sort order is not specified |
maxPageSize | The maximum page size. See pagination |
pageCursor | Include to retrieve the next page of results if you have cursor from a previous response. See pagination |
Example request URLLink copied!
The following example shows how to retrieve all descendants of the hierarchy node with the content item id 4c67ca5a-6050-490a-9859-be20e81ac89d
to a depth of 3 levels.
The same request using the content item's delivery key of ideas-and-advice
is as follows:
ResponseLink copied!
The content-type of the response header is application/json; charset=UTF-8
.
Items will be returned pre-ordered using the specified sort order. The default, and currently only supported, key for sorting is createdDate.
Property | Type | Description |
---|---|---|
responses | array | An array of content |
page | object | responseCount: the number of items returned in the response cursor: If there are further items to retrieve, then cursor will be included in the response. Include this in the pageCursor parameter of the request to get the next page of results. See pagination |
Example responseLink copied!
An example response is shown below:
SortingLink copied!
By default content will be returned sorted by date created, but you can specify your own sort order for the content items returned in the Hierarchy API response. To define a sort option you need to include a trait:sortable
object in your content type schema containing the sort key and the path to one or more properties used to sort the content.
The following trait:sortable
from the page hierarchy node schema example specifies a "default" sort using the property ranking
. If ranking
is equal, the title
property will be used.
You can specify that request returns results using this sorted using this sort key as follows:
Using sort with paginationLink copied!
The Hierarchy API will pre-sort content according to the sort order that you specify in your initial API request. If your content is returned over multiple pages, then you must make sure that you include the same sort key to request each page of data that you specified in the initial request.
PaginationLink copied!
The hierarchy API uses pagination for the response, with up to 100 content items returned for each page. You can specify the maximum page size using the maxPageSize
parameter. If the parameter is not specified then a page size of 50 will be used.
If the number of items returned is greater the page size then the page
object returned in the response will contain a cursor
field. To get the next page of results include this cursor value in the pageCursor
parameter in the subsequent request.
If no cursor
field is included in the response then you've reached the final page of items.
In a request that returns a paginated response, you must use the content item id or delivery key consistently across all requests. For example, you can't use a content item id to request the first page of responses and then use a delivery key to request any subsequent pages.
The maximum supported page sizeLink copied!
The maximum page size for results will vary according to whether you are using the production URL or virtual staging. If you specify a maximum page size greater than the supported page size, then content will be returned up to the maximum page size, and you can retrieve further pages by including pageCursor
in the request until the last page is reached.
Page size exampleLink copied!
In the following example the page size is set to 3, so a maximum of 3 content items will be returned in the response.
The page
object in the response includes cursor
which can be used to retrieve the next page of results.
The value of cursor
from the response can be included in the pageCursor
parameter in the next request as follows:
The next page of results is returned. There is no cursor
included in the response so we know this is the final page of results.
LocalesLink copied!
As with the Content Delivery API, you can use the Hierarchy API to retrieve all of the field level localized content in a hierarchy, or filter it by a specific locale using the locale
parameter.
A simple site menu hierarchy, with field level localized string fields for the name and description, is shown below. We've entered values for the en-GB, fr-FR and de-DE locales.
To retrieve only the content for the fr-FR locale to 3 levels of the hierarchy, use the following request, specifying fr-FR
in the locale
parameter.
If the locale
parameter is not included, then content for all locales is returned.
Locale filteringLink copied!
The Hierarchy API supports the same locale filtering rules as the Content Delivery API:
locale=*
will return content for the first locale that contains a valuelocale=en-*
will return content for the first locale that has "en" as a language code- Multiple locales separated by a comma will be evaluated from left to right until a matching locale is found. For example,
locale=fr-BE,en-GB
will first look for content for thefr-BE
locale and if none is available will look for content with theen-GB
locale. - If a locale cannot be found for a localized property then null will be returned.
Using the Hierarchy API with unpublished contentLink copied!
To retrieve unpublished content using the Hierarchy API, use a virtual staging environment (VSE) in place of the production URL. The virtual staging domain is associated with the hub from which the content is retrieved. A VSE is usually set up for you at the beginning of your project and can be copied from the visualization settings in the Dynamic Content app.
The body of the request and parameters will be the same as when using the production URL.
For the virtual staging domain l05lyya2raie1qr0tzfpiowti.staging.bigcontent.io
the request URL will be as follows:
Example- Retrieving unpublished contentLink copied!
The following example will return the latest version of the descendants of the hierarchy node 4c67ca5a-6050-490a-9859-be20e81ac89d
to a depth of 3 levels. This will include any nodes that have not yet been published, as well as the latest version of published nodes.
When using a virtual staging domain, the latest version of content will be returned. Virtual staging domains pinned to date and time and snapshotIDs are currently not supported, so you cannot use the Hierarchy API in content preview apps. See the Using virtual staging with Dynamic Content page for more details about virtual staging.
Usage notesLink copied!
- Linked content is not returned.
- The
depth
andformat
parameters cannot be specified. - The maximum page size for both the production and virtual staging URL is 100, the default is 50 if no
maxPageSize
is specified.