Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Update Confluence page with Python using REST API?

Jarrod Blomberg
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!
May 18, 2019

Hi,

I am trying to update a confluence page using Python.  I have tried the curl examples that are here in the community forums, but struggling with python.

I am getting 405 and am guessing I have something malformed.  

Any help will be greatly appreciated!

 

print ("NEW PAGE: \n" + new_page) 
print ("Updating page @ " + dataAPI)
headers = {'Content-type': 'application/json', 'Accept' : 'application/json'}
result = requests.post(dataAPI, auth=HTTPBasicAuth(username, password), verify=False, json=new_page, headers=headers )
print (result)

 

Getting Confluence Page Version number
Retriving from https://XXXXXXXX.XXX.XXXX.XXX/confluence/rest/api/content/376006486
old_version : 15, new_version : 16
NEW PAGE:
{"id":"376006486","type":"page","title":"Patterns Summary Data","space":{"key":"XXXXXXX"},"body":{"storage":{"value":"<ac:structured-macro ac:name=\"chart\" ac:schema-version=\"1\" ac:macro-id=\"304d2585-1d15-4851-8867-90bcb2c2c926\"><ac:parameter ac:name=\"dataOrientation\">vertical</ac:parameter><ac:rich-text-body><table class=\"wrapped\" style=\"text-align: left;\"><colgroup><col /><col /></colgroup><tbody><tr><th style=\"text-align: left;\"><p>All Time Status</p></th><th style=\"text-align: left;\"><p>count of Patterns</p></th></tr><tr><td style=\"text-align: left;\"><p>ARCHIVED</p></td> <td style=\"text-align: left;\"><p>1</p></td></tr><tr><td style=\"text-align: left;\"><p>ENDORSED</p></td> <td style=\"text-align: left;\"><p>19</p></td></tr><tr><td style=\"text-align: left;\"><p>PROPOSED</p></td> <td style=\"text-align: left;\"><p>6</p></td></tr><tr><td style=\"text-align: left;\"><p>SOCIALISED</p></td> <td style=\"text-align: left;\"><p>13</p></td></tr><tr><td style=\"text-align: left;\"><p>UNDER DEVELOPMENT</p></td> <td style=\"text-align: left;\"><p>14</p></td></tr><tr><td style=\"text-align: left;\"><p>WITHDRAWN</p></td> <td style=\"text-align: left;\"><p>5</p></td></tr></tbody></table></ac:rich-text-body></ac:structured-macro><p><br /></p>","representation":"storage"}},"version":{"number":16}}}
Updating page @ https://XXXXXXXX.XXX.XXXX.XXX/confluence/rest/api/content/376006486
<Response [405]>
Error : 405 

2 answers

0 votes
Gonchik Tsymzhitov
Community Champion
May 22, 2019
0 votes
Jarrod Blomberg
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!
May 18, 2019 edited

Finally figured it out.     

Should be requests.put, (not request.post)

I've obviously been looking at it for too long!

peter_jayawardena
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!
October 31, 2019

Hi Jarrod, You seemed to have coded something that I just started looking and that is updating a page which has a confluence macro. It seems I have not figured out the correct python code for the insertion of <ac:structured........ I wonder whether you would be kind enough to share that part of the python code?

Thanks

Peter

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events