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
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.
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
This small ugly piece of code can run as user macro with changes in the semantics (fors, variable assigning).
Hope it helps
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.