You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
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?
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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Note: If your array ends at 200 and you have more than 200 attachments, you discovered a bug ;)
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.