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

Earn badges and make progress

You're on your way to the next level! Join the Kudos program to earn points and save your progress.

Deleted user Avatar
Deleted user

Level 1: Seed

25 / 150 points

Next: Root

Avatar

1 badge earned

Collect

Participate in fun challenges

Challenges come and go, but your rewards stay with you. Do more to earn more!

Challenges
Coins

Gift kudos to your peers

What goes around comes around! Share the love by gifting kudos to your peers.

Recognition
Ribbon

Rise up in the ranks

Keep earning points to reach the top of the leaderboard. It resets every quarter so you always have a chance!

Leaderboard

Come for the products,
stay for the community

The Atlassian Community can help you and your team get more value out of Atlassian products and practices.

Atlassian Community about banner
4,467,306
Community Members
 
Community Events
177
Community Groups

HTTP Error 415 while PUT request to rest API

Edited

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

Hi @Nick Artamonov have you find right solution?

0 votes

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

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.

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

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

Atlassian Community Events