You're on your way to the next level! Join the Kudos program to earn points and save your progress.
Level 1: Seed
25 / 150 points
Next: Root
1 badge earned
Challenges come and go, but your rewards stay with you. Do more to earn more!
What goes around comes around! Share the love by gifting kudos to your peers.
Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!
Join now to unlock these features and more
The Atlassian Community can help you and your team get more value out of Atlassian products and practices.
I am attempting to automate the update of Confluence pages using a Python 3.4 script. I first tested using the following cURL:
curl -E jchittum -X PUT -H 'Content-Type: application/json' -d '{"id": "48179230","type": "page","title": "Confluence Api Test","body": {"storage": {"value": "<p> New Content </p>","representation": "storage"}},"ancestors":[{"id": "4595907","type": "page","title": "Luna Release"}],"version": {"number": 5}}' https://ouratlassianserver.com/wiki/rest/api/content/48179230 | python -mjson.tool
This requests updated just fine, and returned the proper JSON.
When I tried to replicate it Python, I get:
{'message': 'javax.ws.rs.WebApplicationException: null', 'statusCode': 500}
When doing a GET operation, everything works fine. Only seeing this on a PUT. We use SSL for authentication
The Python 3.4 code is:
import requests
import json
confPutAddress = "https://ouratlassianserver.com/wiki/rest/api/content/48179230"
cert = "/path/to/cert.pem"
certKey = "path/to/cert.key"
postDict =
{
"id": "48179230",
"type": "page",
"title": "Confluence Api Test",
"version": {
"number": 6
},
"ancestors": [
{
"id": "4595907"
}
],
"type": "page",
"body": {
"storage": {
"value": "<p>New page data.</p>",
"representation": "storage"
}
},
"space": {
'id': 1179650,
'name': 'Luna',
'type': 'global',
}
}
confPUT = requests.put(postAddress, data = postDict, verify=True, cert = (cert, certKey))
print(confPUT.text)
I added space after seeing the following page: https://answers.atlassian.com/questions/38379050
figured out my errors with the help of my team:
1) convert dict to json: convDict = json.dumps(postDict)
postJSON = json.loads(convDict)
2) add headers:
headers = { "content-type" : "application/json" }
3) set requests.put to use JSON
confPUT = requests.put(postAddress, headers = headers, json = postJSON , verify=True, cert = (cert, certKey))
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.