Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in
Celebration

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,560,491
Community Members
 
Community Events
185
Community Groups

Find the total number of attachments in a page using REST API

Using the REST API - /api/content/{id}/child/attachment, how do I find the total number of attachments? 

I don't see a totalSize in the json response. Irrespective of the limit parameter value, the size of the result set is 200.

Using the UI, I can visually see the number Attachments (650) when looking at the page properties. 

Is there a way to get this number using REST API? 

 

2 answers

1 vote
tshenolo
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
Apr 28, 2023 • edited Apr 29, 2023


The attachment REST API call does not return the total number of attachments. 
You have to do something called API pagination and add up all sizes to get the total size.

For reference: REST API - /api/content/{id}/child/attachment?start=0&limit=200

Also the maximum limit you can set for the attachment API call is 200. ie limit=200.

The trick is to increase the start parameter by 200 and check if the json returned by the API call has  _links->next .

For example you can do the following API calls:

YOUR_SERVER/api/content/{id}/child/attachment?start=0&limit=200
YOUR_SERVER/api/content/{id}/child/attachment?start=200&limit=200
YOUR_SERVER/api/content/{id}/child/attachment?start=400&limit=200
YOUR_SERVER/api/content/{id}/child/attachment?start=600&limit=200

until the json returned does not contain _links->next

Add up all the sizes for each call to get the total number of attachments.


Please check the following sample code:  
https://github.com/tshenolo/confluence-restapi-functions

Don't forget to give the repo a star if you find the sample code useful.

0 votes
Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 23, 2021

Dear @InfoSec ,

unfortunatelly there is no specific REST request for the amount of attachments of one page, but with GET /rest/api/content/{id}/child/attachment and reading the JSON entity "size" you get the number you want.

If not, you can still do pagination and count JSON array opjects.

So long

Thomas

Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Apr 23, 2021

Note: If your array ends at 200 and you have more than 200 attachments, you discovered a bug ;)

Thomas Deiler
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
May 05, 2021

Dear @InfoSec ,

don't forget to press the "green accept answer" button to indicate other readers the successful answering of your question.

So long
Thomas

I am also seeing that my array is ending at 200 even though I give a higher limit value.

How can this issue be resolved if this is a bug?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events