I would like to write content to an existing page using the REST API, here's my current script:
#!/usr/bin/python
#
# Reference: http://isbullsh.it/2012/06/Rest-api-in-python/
#
import sys
import getpass
import json
import requests
BASE_URL = "http://confluence.XXXXXX.com/rest/api/content"
PAGEID = 9470040
def main():
username = raw_input('login: ')
passwd = getpass.getpass()
url = "{base}/{pageid}".format(
base = BASE_URL, pageid = PAGEID)
data = json.dumps(
{
'id' : '%d' % PAGEID,
'type' : 'page',
'title' : 'Sandbox',
'space' : {'key' : 'HSWc'},
'body' :
{
'storage' :
{
'representation' : 'storage',
'value' : """
<table>
<tbody>
<tr>
<th>Hello</th>
<th>World</th>
</tr>
<tr>
<td>Nick</td>
<td>Rocks!</td>
</tr>
</tbody>
</table>
"""
}
}
})
r = requests.put(
url,
data = data,
auth = (username, passwd),
headers = {
'Content-Type' : 'application/json',
'Accept' : 'application/json'
}
)
r.raise_for_status()
if __name__ == "__main__" : main()But I'm getting "requests.exceptions.HTTPError: 400 Client Error: Bad Request"
There currently isn't any working documentation for using the REST API. Please help!