0

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)
PS376
  • 539
  • 8
  • 13
  • Have you tried changing `data=pageData` to `data=json.dumps(pageData)` as the [documentation](https://developer.atlassian.com/confdev/confluence-rest-api/confluence-rest-api-examples#ConfluenceRESTAPIExamples-Addacommenttoapage(python)) appears to have it as a string. – Cory Shay May 12 '16 at 18:24
  • Yes, that was what I had it before, and it doesn't change anything. – PS376 May 12 '16 at 21:15

1 Answers1

1

I found the solution here: How do you post a comment to Atlassian confluence using their REST api?. You basically need to extend your container tag. Confluence documentation doesn't mention this at all. :(

pageData = {'type':'comment', 
    'container':{'id': str(parentPage), 
        'type':'page', 
        'status': 'current'
    }, 
    'body':{
        'storage':{
            'value':"<p>New comment!</p>", 
            'representation':'storage'
        }
    }
}
milo526
  • 5,012
  • 5
  • 41
  • 60
kirillka
  • 181
  • 5