How to add or remove page restrictions Python

gurgen2727 April 26, 2018

Hi

 

I couldn't find anywhere how I can add or remove page restrictions for user and group by using Python ?

 

It can be any API( xmlrpc or REST API), just help me to do that ?

 

potentially I just need to remove all permission for everybody and then add only for one user

2 answers

1 vote
Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 27, 2018

Hi Gurgen,

You can see the XMLRPC documentation for setting permissions here, specifically setContentPermissions:

https://developer.atlassian.com/server/confluence/remote-confluence-methods/#permissions

If you search for some further XMLRPC examples, they shouldn't be too hard to find.

Stephen Deutsch
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
April 27, 2018

And in case someone is curious about the Cloud version, you can already set page permissions via REST:

https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-restriction-put

gurgen2727 April 28, 2018

Hi Stephen

 

Thank you very much.

 

Is there a way to do this by REST API ? seems that feature is in experimental API. I found one way, but that is still in 'experimental' s

PUT https://confluence/rest/experimental/content/<id>/restriction/byOperation/read/user?userName=billgates

 

So I am worried whether I can use xmlrpc deprecated method for customers. How long this is going to be supported in XMLRPC ?

0 votes
AnnWorley
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
April 26, 2018

Hi Gurgen,

I don't know how to remove restrictions using the Python with the REST API. Based on the Confluence REST API Documentation it looks like the API will let you GET the restrictions but does not provide a way to update them.

Please consider SQL as an alternative, as described in: How to remove all restrictions from a specific page via the database.

Thanks,

Ann

gurgen2727 April 26, 2018

Thanks I have found that, but I don't need DB.

 

any suggestion, by using xmlrpc ? anyway ? if you provide me API I can write Python code myself. I need to do that in Python.

fwoon
Contributor
May 28, 2019

most prob you can update the permissions and that should remove whatever you needed.

you can omit the group or user if you don't require to update either one of them

url = 'https://your-confluence.com/rest/experimental/content/{id}/restriction'
headers = { "Accept": "application/json", "Content-Type": "application/json" }
payload = json.dumps( [
{
"operation": "update",
"restrictions": {
"user": [
{ "type": "known",
"username": "<string>",
"userKey": "<string>",
"accountId": "<string>"
}],
"group": [
{
"type": "<string>",
"name": "<string>",
}]
}
}
] )

r = requests.put( url, verify=False, data=payload, headers=headers, auth=(username, passwd) )

 Take a look at https://developer.atlassian.com/cloud/confluence/rest/#api-content-id-restriction-put for reference...try to do a get permission on the page first to understand what kinda operation there is...do not use administer as the operation...that's for cloud

John_Huang
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!
April 29, 2020

This one doesn't work either. 

Helen Song December 18, 2020

@fwoon @John_Huang  have you execute it successfully or not?

fwoon
Contributor
December 18, 2020

@Helen Song 

Yes i most definitely can. Just verified it on 7.4.1 Confluence Server.

Take note that this is a page restriction update, not space permission restriction.

Again to reiterate, make sure you know the group name if you are adding the group, if it's an individual, make sure you get the userKey, username, displayName. If you don't know, simply do a get on a page that has that user/group on the page restrictions

url = BASE_URL + pageId + PERM_URL
headers = { "X-Atlassian-Token": "nocheck" }
payload = {
"expand" : "update.restrictions.user,read.restrictions.group,read.restrictions.user,update.restrictions.group"
}
r = requests.get(url, verify=False, headers=headers, params=payload, auth=(username, passwd))

#Check for successful call
if r.status_code == 200:
print r.text

Helen Song December 20, 2020

Thank you very much.

Do you know how to lock the page by groovy or REST API?

Helen Song December 20, 2020

It looks like that is method of update read permission, is it possible to lock one page edit permission but keep all read permission as before?

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events