How to get attachments for a specific version of a page

Hello,

I’m trying to get the attachments of a page using the API. I’m using an API key, and to get a list of attachments i’m calling:

https://{company}.atlassian.net/wiki/rest/api/content/{pageID}/child/attachment

Once I get the attachment ID, I download it (this time using OAuth2 / 3LO) with

https://api.atlassian.com/ex/confluence/{cloudID}/rest/api/content/{pageID}/child/attachment/{attachmentID}/download

The results are correct. However, the first call returns all the attachments of all the versions of the page, not just the current version. For example, say the page has the following attachments

  • Page version 1:
    • Image1.jpg
    • Image2.jpg
    • Image3.jpg
    • Image4.jpg
  • Page version 2 (current):
    • ImageAlbum.pdf (the images were deleted and merged into a single file)

The results includes all 5 files. However, our app should see only the most recent one (in this case ImageAlbum.pdf). The attachment objects returned don’t have any mention of the version of the parent page where they are located, so I can’t filter them either.

Is there a way to obtain the attachments of just the last version of a page using the API? Alternatively, with the ID of the page and the attachment, can I check if the attachment is present in the last version of the page?

Not sure if there’s a better solution but you could parse the page’s ADF and search for all media nodes where attrs.type = file. That should return all attachments for the current version of the page.

I managed to solve it by searching the page with

https://{baseURL}.atlassian.net/wiki/rest/api/search?cql=id="{pageID}"&expand=content.body.storage

There, inside the body.storage.value field, there’s a xml list with all the current files.