Get Space page hierarchy using the REST api

Mathieu Yargeau March 13, 2018

There was a question asked a while ago, but with no helpful answer.
https://community.atlassian.com/t5/Confluence-questions/Get-Space-page-hierarchy-using-the-REST-api/qaq-p/351963

 

In a webpage, I want to build a tree view of the pages of a space, and maybe put them in a dropdown so the user can select one.

 

I am able to do a REST call to /rest/api/space/{spaceKey}/content to get the pages, but they are all in a list, with no hierarchy, and the ancestor field is always empty.

 

I am able to get only the root page with the same api, but setting the depth to "root". From there, I could do a REST call to get the children of that page, then do a REST call for every child to get their children and so on...

This would mean a number of REST calls equal to the number of pages, which is not great. Is there a better way to do it?

3 answers

1 vote
Kim Wallace March 15, 2021

Helen's workarounds are very helpful - and point out a glaring omission within Confluence. The content management tool UI is severely underpowered. This question has been in the community since 2016 and STILL doesn't have an adequate response from Atlassian. 

0 votes
Helen Setchell March 26, 2020

In case it helps someone else finding their way here - https://community.developer.atlassian.com/t/get-space-page-hierarchy-using-the-rest-api/15999/11 has more answers

0 votes
AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
March 13, 2018

Hi Mathieu,

You could use the Page Tree Macro to display the tree view of the pages on a Confluence page. 

Here is another resource for REST questions if this forum doesn't answer satisfactorily.

Thanks,

Ann

Mathieu Yargeau March 13, 2018

Thank you for the suggestion. Page Tree Macro is fine, but can only be used in a Confluence Page, and after trying it, you cannot use it to select a page as part of a form.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events