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.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.