Way to find all pages

Kevin Lu July 18, 2016

Via the Confluence Cloud REST API, is there anyway to obtain all pages that have no parents (AKA finding all pages that are at the top of their hierarchy tree)?

1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

1 vote
Answer accepted
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 19, 2016

There's a few options, but either way, it seems like you'll have to go space by space.

You can use the json-rpc/confluenceservice-v2/getTopLevelPages call if you are OK with using JSON-RPC (POST ["spacekey"] as data).

Otherwise, to do it purely with the REST API, you can get all spaces via the following REST call:

https://xxxx.atlassian.net/wiki/rest/api/space?expand=homepage&type=global&start=0

and then call it with start+=25 until size != 25 (because it returns only 25 at a time). Make sure you keep track of each results[#].key (space key) and results[#].homepage.id (page ID of the homepage of that space).

Then you should call the following for each space:

https://xxxx.atlassian.net/wiki/rest/api/content/search?cql=space%3D<spacekey>%20and%20type%3Dpage%20and%20ancestor!%3D<homepageId>

where <spacekey> is the spacekey of the space and <homepageId> is the homepage page ID. If you want to exclude the homepage from the results (because the homepage also has no parents), then you can simply add the following on the end of the above REST call:

%20and%20id!%3D<homepageId>

Kevin Lu July 19, 2016

Tried posting ["spacekey"] and it seems like I'm not allowed to view that space, but that's okay. The other method should work perfectly! Is there a way that I can do a count of all the spaces to see how big of a dataset I'm working with (I don't have access to the server or any commands that require restrictive admin rights)?

 

Thanks so much!

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 20, 2016

by ["spacekey"] I meant that you need to subsititute the actual space key for the word spacekey smile

You should be able to find out a the total number of spaces with:

https://xxx.atlassian.net/wiki/rest/searchv3/1.0/search?startIndex=0&type=spacedesc

and if you want to see all archived spaces too, then just add &includeArchivedSpaces=true to the end wink

TAGS
AUG Leaders

Atlassian Community Events