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,556,237
Community Members
 
Community Events
184
Community Groups

Finding storage usage of Confluence space and page using REST API

Hi, 

I try to fetch the consumed storage of our spaces by using the python script as documented here: https://confluence.atlassian.com/confkb/finding-storage-usage-of-confluence-space-and-page-using-rest-api-1063555292.html

The script is running fine but stops after 25 spaces. I can't find any limiter within the script, so maybe the REST API is limiting. 

Can somebody help me out how to fetch all results?

 

Regards,

Jonny

2 answers

1 vote
marc -Collabello--Phase Locked-
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
Aug 29, 2022

It seems the python script does not follow the `_next` links, if there are more than 25 results.

I believe the script needs to be modified for this.

Hi There,

is there anyone who has already updated the script?

Thanks

Patrick

I got the Solution and edited the Script to get 500 results:

# This code sample uses the 'requests' 'json' 'csv' library:
import requests
import json
import csv

#INSERT "USER", "TOKEN", "BASE_URL" HERE
USER="User"
TOKEN="Token"
BASE_URL="https://xxxxxxxxx.atlassian.net"

with open('per_page.csv', 'w') as pagecsvfile, open('per_space.csv', 'w') as spacecsvfile:
perPageWriter = csv.writer(pagecsvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
perSpaceWriter = csv.writer(spacecsvfile, delimiter=',', quotechar='|', quoting=csv.QUOTE_MINIMAL)
perPageWriter.writerow(['pageid','attachment_size(byte)'])
perSpaceWriter.writerow(['space_name','space_key','attachment_size(byte)'])

headers = {
"Accept": "application/json"
}

response = requests.request(
"GET",
BASE_URL + "/wiki/rest/api/space?limit=500",
headers=headers,
auth=(USER,TOKEN)
)

site_attachment_volume = 0

#Get all space keys
space_key_results = json.loads(response.text)["results"]
for space in space_key_results:
space_attachment_volume = 0
#Get related page IDs from space keys
response = requests.request(
"GET",
BASE_URL + "/wiki/rest/api/space/" + space["key"] + "/content",
headers=headers,
auth=(USER,TOKEN)

)
print("Space Key: " + space["key"])
page_results = json.loads(response.text)["page"]["results"]
for page in page_results:
page_attachment_volume = 0
#Get attachments from each page
print(" " + "Page ID: " + page["id"])
response = requests.request(
"GET",
BASE_URL + "/wiki/rest/api/content/" + page["id"] + "/child/attachment",
headers=headers,
auth=(USER,TOKEN)
)
attachment_results = json.loads(response.text)["results"]
for attachment in attachment_results:
print(" " + "Attachment Name: " + json.dumps(attachment["title"]) + ", " + json.dumps(attachment["extensions"]["fileSize"]) + " bytes")
page_attachment_volume += int(json.dumps(attachment["extensions"]["fileSize"]))

space_attachment_volume += page_attachment_volume
print(" -->" + "PAGE TOTAL: " + str(page_attachment_volume))

#Write to CSV
perPageWriter.writerow([page["id"],str(page_attachment_volume)])

print("\n " + "SPACE TOTAL: " + str(space_attachment_volume) + " bytes")
print("----------")

#Write to CSV
perSpaceWriter.writerow([space["name"],space["key"],str(space_attachment_volume)])

 

 

 

 

 

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
PERMISSIONS LEVEL
Site Admin
TAGS
AUG Leaders

Atlassian Community Events