I'm trying to run the example on the Confluence REST API Python site to add comments to a wiki page. Everything until parentPage works (as in, it gets the correct page from our intranet wiki), but when I run the requests.post, it does not actually add a comment to the page found. Instead printResponse(r), prints out all pages in the wiki (not the page I found).
I have the following script:
#!/usr/bin/python
import requests, json
base_url = 'http://intranet.company.com/rest/api/content'
username = 'username'
password = 'password'
def printResponse(r):
print '{} {}\n'.format(json.dumps(r.json(), sort_keys=True, indent=4, separators=(',', ': ')), r)
r = requests.get(base_url,
params={'title' : 'Space M Homepage'},
auth=(username, password))
printResponse(r)
parentPage = r.json()['results'][0]
pageData = {'type':'comment', 'container':parentPage,
'body':{'storage':{'value':"<p>New comment!</p>",'representation':'storage'}}}
r = requests.post(base_url,
data=json.dumps(pageData),
auth=(username,password),
headers=({'Content-Type':'application/json'}))
printResponse(r)