Hello Community,
I am building a portal that allows users to see details regarding their Confluence spaces.
My plan is to use the Confluence Cloud REST API v2, and I have found the following endpoint that could help my case: Get space by id. The problem is that the endpoint requires space IDs, that I did not manage to find on the web UI.
Also, our users are familiar with the Confluence space key and it would be great if we could utilise the space key, but the linked endpoint only accepts integers as IDs. I found that the v1 API still works with space keys, but I can see that the endpoint is deprecated.
Therefore, I am interested in two things:
Thanks a lot in advance!
Hello Dániel,
I was looking for the same API endpoint and noticed that most calls utilize space ID instead of space key. So I created a simple python3 script to get the space ID given a specific space Key:
import requests
from requests.auth import HTTPBasicAuth
import json
site = "https://<YOUR_SITE_NAME>.atlassian.net/"
auth = HTTPBasicAuth("<YOUR_EMAIL>", "<YOUR_SITE_NAME>")
headers = {
"Accept": "application/json"}
next_page = "wiki/api/v2/spaces/"
listSpace = {} #initialize dictory
while next_page:
url = site+next_page
response = requests.request(
"GET",
url,
headers=headers,
auth=auth
)
if response.status_code == 200:
data = response.text
space_data = json.loads(data)
#pagination
if 'next' in space_data['_links']:
next_page = space_data['_links']['next']
#getting data for the dictionary
for x in space_data['results']:
spacekey = x['key'] #Getting all space keys
spaceid = x['id'] #Getting all space ids
listSpace[spacekey]=spaceid
else:
break
key = input("What is the spacekey? \n") #Asks the user for the space key.
print(listSpace.get(key))
I hope this helps even though it does not answer your questions,
Best Regards,
Adriana
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.