Hi dear community,
I am trying to update a Confluence page with python. At first I was trying to use the Atlassian python library but I kept getting a 415 unsupported media type error.
I found this bug report so I decided to bypass the library and build a regular PUT request in Python just like Atlassian has documented on https://developer.atlassian.com/cloud/confluence/rest/v2/api-group-page/#api-pages-id-put
I'm still getting the 415. It works fine with curl so I'm wondering: does this work for anyone?
Code I'm using:
def update_page():
auth = HTTPBasicAuth("example@email.com", "supersecrettoken")
headers = {
"Accept": "application/json",
"Content-Type": "application/json"
}
payload = json.dumps({
"id": "240156673",
"status": "current",
"title": "My Page Title",
"body": {
"representation": "storage",
"value": "Hello World"
},
"version": {
"number": 5,
"message": "new version"
}
})
print(payload)
response = requests.put(
"http://company.atlassian.net/wiki/api/v2/pages/240156673",
json=payload,
headers={
"Accept": "application/json",
"Content-Type": "application/json"},
auth=auth
)
print(response.status_code)
print(response.request.body)
print(response.request.headers)
print(json.dumps(json.loads(response.text), sort_keys=True, indent=4, separators=(",", ": ")))
status = update_page()
The result is:
{
"errors": [
{
"code": "UNSUPPORTED_MEDIA_TYPE",
"detail": null,
"status": 415,
"title": "org.springframework.web.HttpMediaTypeNotSupportedException: Content type '' not supported"
}
]
}
And what I think is very strange:
When sending the request to https://httpbin.org/anything instead I do get my header and body returned.
Hi @Charlie Misonne ,
maybe you need to replace the line
```
json=payload,
```
with
```
data=payload,
```
as you've done a `json.dumps()` call.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
thanks for pointing that out.
I had been playing around with the different options before but json=payload or data=payload both return a 415.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Want to leave your mark on Confluence? One winner will have their whiteboard design added into Confluence for all users to access! This is your chance to showcase your creativity, help others, and gain recognition in the Confluence community.
Share your template today!Online forums and learning are now in one easy-to-use experience.
By continuing, you accept the updated Community Terms of Use and acknowledge the Privacy Policy. Your public name, photo, and achievements may be publicly visible and available in search engines.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.