In my previous post I explored how to access the Confluence Cloud Space Permissions API endpoint.
This Python script extends that, and gives a user a permission set in all Spaces in Confluence. This could be useful if you wanted to give one person Administrative rights on all Spaces in Confluence, for example.
Note that the user must first have READ/SPACE permission before any other permissions can be granted.
from requests.models import Response
import requests
import json
headers = {
'Authorization': 'Basic <Base-64 encoded username and password>',
'Content-Type': 'application/json',
'Accept': 'application/json',
}
userID = '<user ID (not name)>'
url='https://<url>.atlassian.net/wiki/rest/api/space/'
resp = requests.get(url, headers=headers)
data = json.loads(resp.text)
for lines in data["results"]:
url="https://<url>.atlassian.net/wiki/rest/api/space/"+lines["key"] + '/permission'
dictionary = {"subject":{"type":"user","identifier": userID},"operation":{"key":"read","target":"space"},"_links":{}}
data = data=json.dumps(dictionary)
try:
response = requests.post(url=url, headers=headers, data=data)
print(response.content)
except:
print("Could not add permissions to Space " + lines["key"])
Leave a Reply