get list of all documents across whole Confluence

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

This widget could not be displayed.
Davin Studer Community Champion Apr 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.

This widget could not be displayed.

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
Community showcase
Posted Sep 17, 2018 in Confluence

Why start from scratch? Introducing four new templates for Confluence Cloud

Hi my Community friends!  For those who don't know me, I'm a product marketer on the Confluence Cloud team - nice to meet you! For those of you who do, you know that I've been all up in your Co...

602 views 8 6
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you