2
1
0

I'm currently using the Confluence REST API to develop a custom application outside of our Confluence installation.

I'd like to be able to list ALL attachments associated with a space. This includes attachments of rootpages, children, children's children, children's children's children, and so on... Currently, it doesn't seem there is an easy way to do this. I know I can use the expand tag to manually specify how deep I'd like to go to unveil attachments. For example, to get the rootpages attachments and their immediate children's and I can do something like this:

/space/{key}?expand=rootpages.content.attachments,rootpages.content.children.content.attachments

This seems awfully verbose, to begin with. Also, I'm only getting the first level of children's information.

It appears as if this functionality is available in the full version of the product via this URL: /confluence/spaces/listattachmentsforspace.action?key={key}.

Any ideas?

Thanks!

    CommentAdd your comment...

    3 answers

    1.  
      2
      1
      0

      The API doesn't have a single method to return all attachments in a space; however, I recently created a Python script that fetches all pages in a space and iterates through them to perform various testing tasks. I modified it to get attachments for each space and store them.

      The print at the end is just meant to be a quick example of how you can retrieve the various bits of data to suit your needs. If you ever want to know the keys in a dict, you can user list(dict) and it will print all the keys you can pull values from.

      1. Joel Martinez

        Thank you, I appreciate your approach.

        However, can't the pages themselves have children as well? Unless, the "getPages" call actually gets ALL pages, including every page descendant. Otherwise, I imagine you'd need a recursive solution to traverse to the bottom of the page hierarchy.

      2. Adam Laskowski

        The getPages call does get all pages in a space, regardless of what level in the hierarchy they exist. The call itself is explained here:

        https://developer.atlassian.com/display/CONFDEV/Confluence+XML-RPC+and+SOAP+APIs#ConfluenceXML-RPCandSOAPAPIs-Pages

      CommentAdd your comment...
    2.  
      2
      1
      0

      Hi, I think that all attachments are not link to a page so is there an other way to get all those attachments than using getPages() function?

      Thx

      1. Adam Laskowski

        Attachment objects store the pageid for the page they are associated with, which is why the script uses getPages() to populate a list of pageids:

        https://developer.atlassian.com/display/CONFDEV/Remote+Confluence+Data+Objects#RemoteConfluenceDataObjects-attachmentAttachment

        I don't know of a better way to get the attachments via the API. You could directly query the database as an alternative method by joining the content and attachments tables.

      CommentAdd your comment...
    3.  
      1
      0
      -1

      Hi!

      Maybe this post is a little bit old (or too old) but I needed to retrieve all the fonts in our company's wiki, and your Python script was useful, however incomplete, as it only returns one page attachments (you use allattachments[0] and that's the problem). Also now is confluence2 object and, in my case, we don't use the port 8080.

      Here is your code modified to my preferences (you can change the attachment filetype or just remove it):

      Regards,

        CommentAdd your comment...