Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

HTTP Error 415 while PUT request to rest API

Nick Artamonov February 25, 2022

I use instructions to make PUT request to rest API

auth_basic = HTTPBasicAuth('<login>', '<password>')

payload_data = {
"version": {
"number": 3
},
"title": "My new title",
"type": "page",
"body": {
"storage": {
"value": "<p>New page data.</p>",
"representation": "storage"
}
}
}

url_put = 'https://<host>/rest/api/content/64534329'

r = requests.put(url_put, data=json.dumps(payload_data), auth=auth_basic,
headers=({'Content-Type': 'application/json',
"Accept": "application/json",
"Origin": 'https://<host>'}))


 and i received HTTP ERROR 415. With attlassian module for python i received same HTTP ERROR:

from atlassian import Confluence
confluence = Confluence(
url='https://<host>',
username='<user>',
password='<pass>')
confluence.update_page(64534329, 'Created From REST API - updated', 'Test Body',
parent_id=None, type='page', representation='storage',
minor_edit=False)

I tried trial version of cloud confluence and same code working fine, but our local server works fine only with GET requests to api, not PUT. While i trying python requests i don`t see any error strings in confluence logs.

With CURL i received HTTP ERROR 500

 

curl -s -L --max-redirs 5 -u user:password -X PUT https://<host>/rest/api/content/64534329 -d '{"title": "Тестовая страница для REST API", "type": "page", "body": {"storage": {"value": "page_body", "representation": "storage"}}, "version": {"number": 3}}' -H "Content-Type: application/json"

and in logs i view next string:

2022-02-25 11:23:56,143 ERROR [http-nio-8090-exec-272] [rest.api.model.ExceptionConverter] convertServiceException No status code found for exception, converting to internal server error :
-- url: /confluence/rest/api/content/64534329 | traceId: 67f1176c57724f8e | userName: <User>
java.io.EOFException: No content to map to Object due to end of input

But GET request with CURL works fine and returns this page.

2 answers

0 votes
Александр Чиликин September 1, 2022

Hi @Nick Artamonov have you find right solution?

0 votes
Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2022

415 means unsupported content, basically you're sending a bunch of data to some endpoint without telling it what kind of data it is, so it defaults to plain text

Try adding Content-Type: application/json to the request such as in this example https://developer.atlassian.com/server/confluence/confluence-rest-api-examples/#update-a-page

Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2022

Oh nevermind I noticed later you do include that header in python. Eh not sure then, maybe there's something wrong with the syntax? I don't like python and don't use it for REST, but I know that the same thing works with cURL for me pretty much just in the example inside the documentation.

Radek Dostál
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
February 25, 2022

So to make up for bad comment, this is the latest format I used in one script which modifies a page:

curl -X PUT \
-b "$apiToken_Confluence" \
-s -S \
-H 'Content-Type: application/json' \
-d @$tmpDir/put-data.json \
--url "$URL" \
-o $tmpDir/put-response

 

And from what I see what's in that put-data.json

echo '{"id":"'"${CONFLUENCE_PAGEID}"'","title":"'"$pageTitle"'","version": {"number": '"$nextVersion"'}, "type": "page", "body":{"storage":{"value":"'"$(cat $tmpDir/page.body.storage-updated | sed 's#"#\\"#g')"'","representation":"storage"}}}' > $tmpDir/put-data.json

 

Perhaps you can spot some differences and compare the two, this one currently is working with 7.13.4

Nick Artamonov February 27, 2022

My code wery fine works to cloud confluence, but not working with our local server.

Maybe because our site is behind haproxy, or local server settings is not correct at all.

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events