How to update a page with Python using REST API?

I am trying to set a Confluence page restriction using Python and the Confluence REST API.  I am not having any luck on Confluence 6.0.4

My code snippet is

create={ "type":"page",
"title":"1.1.23",
# "restrictions":[{"operation": "read","type":"group", "name": "cam-1.3"}],
"read":{"operation":"read","restrictions":{"group":{"results":[{"type":"group","name":"cam-1.3"}]}}},
"ancestors":[{"id":"25994717"}],
"space":{"key":"~danciarlette-admin"},
"body":{"storage":{"value":'<p><ac:structured-macro ac:name="attachments" ac:schema-version="1" ac:macro-id="ec23f1c2-0df6-437d-9ad0-d1e0b1248811"><ac:parameter ac:name="upload">true</ac:parameter></ac:structured-macro></p>',"representation":"storage"}}
}

r=requests.post(url, data=json.dumps(create),auth=('admin', 'admin'), headers=({'Content-Type':'application/json'}))

It creates the page but the restrictions are not there.

Any help or pointing me to a resource would be great.

Thanks.

1 answer

0 vote

Hi, Daniel.

The restrictions cannot be set while creating a page through the REST API. And currently, there's no official REST API call that will allow you to set restrictions in Confluence pages/spaces.

However, I was able to find two other topics in our community with alternatives to set it:

  1. This topic covers how to add permissions using the CLI plugin: https://community.atlassian.com/t5/Answers-Developer-Questions/How-to-set-page-Restrictions-to-users-using-Confluence-APIs/qaq-p/529144
  2. And on this topic, another user was able to add restrictions through an experimental REST API call: https://community.atlassian.com/t5/Answers-Developer-Questions/Set-Page-Restrictions-using-Confluence-REST-API-v5-5/qaq-p/487662

In short, you'll have to make at least two calls to get your page created with the proper restrictions.

I hope it helps, Daniel! :)

- Mallmann

Suggest an answer

Log in or Sign up to answer
Atlassian Community Anniversary

Happy Anniversary, Atlassian Community!

This community is celebrating its one-year anniversary and Atlassian co-founder Mike Cannon-Brookes has all the feels.

Read more
Community showcase
Kesha Thillainayagam
Posted Apr 13, 2018 in Confluence

We want to hear how your non-technical teams are using Confluence!

Hi Community! Kesha (kay-sha) from the Confluence marketing team here! Can you share stories with us on how your non-technical (think Marketing, Sales, HR, legal, etc.) teams are using Confluen...

2,927 views 27 12
Join discussion

Atlassian User Groups

Connect with like-minded Atlassian users at free events near you!

Find a group

Connect with like-minded Atlassian users at free events near you!

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you