REST API call to return page attachments (created or modified after a certain date)

Harvey Bennett February 19, 2020

Hello community,

 

There was a post from a while back asking about how to get attachments of a confluence page via REST API. https://community.atlassian.com/t5/Answers-Developer-Questions/confluence-pages-get-attached-files-via-REST-API/qaq-p/529873

 

The reason I'm asking is I have over 1000 attachments on a page and its growing every day. The problem is I don't want to see the old attachments anymore in my REST call because the data has already been handled from them and I just want to look at newer attachments only with the call. I was wondering if this could be taken a step further somehow and get attachments for a page within a specified time range or greater than a certain start time (this can based off either its modified or creation date)? I didn't see any attributes showing dates in the returned JSON but maybe someone knows a way to check for this :/

 

Thanks

1 answer

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.
February 19, 2020

You could use the CQL search REST API like this. Replace {Your Server} with your Confluence server and {Containing Page ID} with the page id that the attachments are attached to. This will get attachments to that page that are created or updated in the last 14 days.

https://{Your Server}/rest/api/search?cql=type%20%3D%20attachment%20and%20container%20%3D%20{Containing Page ID}%20and%20(created%20%3E%3D%20startOfDay(%22-14d%22)%20or%20lastmodified%20%3E%3D%20startOfDay(%22-14d%22))

 This is the CQL not URL encoded ...

type = attachment and container = {Containing Page ID} and (created >= startOfDay("-14d") or lastmodified >= startOfDay("-14d"))
Harvey Bennett February 21, 2020

I was not even aware that Confluence had its own query language. This was exactly what I needed. Thank you!

Like Davin Studer likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events