get list of all documents across whole Confluence

Christine Medley April 23, 2015

Hi,

I am trying to create a list of all the documents we have attached/stored across our entire Confluence site. I would like this list so I can attach labels to each document. These labels are important as we use the "content by label" macro to populate other pages.

I can only find the space attachments macro - but that will only show me one space at a time. I'd really like to do this once - not 42 times for each space.

Thank you for any help you can provide with this.

Christine

2 answers

1 accepted

1 vote
Answer accepted
Davin Studer
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.
April 27, 2015

Since you are on the Cloud version I think the best way would be to use the REST API to get them.

You would use something like this url.

https://{server}/rest/api/content?limit=500&start=0

 The REST API will only return at the max 500 results. So, if your site has more that 500 pages you will have to do multiple requests. Like this ...

https://{server}/rest/api/content?limit=500&start=0
https://{server}/rest/api/content?limit=500&start=500
https://{server}/rest/api/content?limit=500&start=1000
https://{server}/rest/api/content?limit=500&start=1500 
etc...

At the end of the JSON object there is a property for the next and previous URL to help with pagination.

image2015-4-27 9:14:43.png

Also, notice the limit and size properties in the above screen shot. As you go though the pagination when size finally becomes less than the limit or there is no next property (pick your method) you know you have reached the last page or results.

One final thing to note make sure you use a user that can see all pages. The REST API respects the Confluence restrictions. So, if you don't use a user that has access to everything then you might have pages left out of the results.

0 votes
Panos
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.
April 23, 2015

Depending on how many pages each space has and your patience you can do something like

List<Space> spaces=spaceManager.getAllSpaces();
for(Space space:spaces)
{
	List<Page> pages=pageManager.getPages(space,true);
	for(Page page:pages)
	{
		Attachment attachment=attachmentManager.getLatestVersionsOfAttachments(
			page.getContentEntityObject());
		//do something with that attachment
	}
}

From that point you can e.g. inject all attachment objects in a macro and render them in a velocity template and add labels with rest calls. Or if you have some pattern at labeling you can do it at below the //do something with that attachment, or something different smile

 

This small ugly piece of code can run as user macro with changes in the semantics (fors, variable assigning).

Hope it helps

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events