Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

How to get pages with no attachment via REST api

Ilcin
Contributor
January 11, 2019

Hi,

I'm trying to write a script that moves all storage pages with no attachments to another page as their child so that they can be deleted later. I need a way to specify that the number of attachments is zero in my fetch request that I send out.
So far it takes all storage pages, but I only want the pages with no attachments to it. 

Is there a way to do that?

Thanks!

1 answer

1 accepted

1 vote
Answer accepted
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 11, 2019

Hello Splashy,

Using the API in conjunction with a script to do this task is a great idea. Ideally, you would want to get to the result in the least amount of effort.

Here is how I would approach this task:

  1. Create an array of all pages in a space
    1. api/content (GET content)
  2. For each page (Using the ID), check if an attachment is present.
    1. api/content/{id}/child/attachment
    2. IF(attachment = Present) {DO NOTHING.}
    3. Else{DO SOMETHING}
  3. Repeat for each space

This would be the shortest path to check all pages in a space to see if they have an attachment.

Regards,
Stephen Sifers

Ilcin
Contributor
January 18, 2019

Hello Stephen,

thank you so much for the input (and provided links, I'm a newbie working with APIs and scripts so they helped a lot)!
What I had to do was delete move the child pages of one specific page and not for multiple pages. So i just adapted your suggestion.
I used a for loop, getting the attachments for each page and checking for their type and size, so that I could sort out all child pages without an attachment.

I just have a tiny question left. Is there a limit for how many pages I can get with the GET request? I know the default is 50.

Regards,
splashy

Like Stephen Sifers likes this
Stephen Sifers
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
January 18, 2019

Hello again Splashy,

Very glad to hear you're able to find a solution!

For the follow up question, the page limit max I have seen is 200 pages(items) to be returned. However, you can set the page limit anywhere between 1-200. An example of this would be as follows:

"http://localhost:8080/confluence/rest/api/space/ds/content/page?limit=200"

There is a whole document which explains why this exists, how it works and when to use it. You may find that document at Pagination in the REST API.

Very glad to be of assistance, keep the great questions coming!

Regards,
Stephen Sifers

Like # people like this
Ilcin
Contributor
January 18, 2019

Hello Stephen,

thank you for your fast and informative answer! I will take a look into the document you provided and finish up my script.

I wish you a good weekend!

Regards,
splashy

Like Stephen Sifers likes this

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events