I'm currently using Confluence server and I'm running into this error when I try to create a new page using the REST API. I am currently using an HTML macro that makes GET & POST requests using the Fetch API. I currently have no issues when making GET requests, only issues with POST requests.
function createPage() {
let url = "http://exampledomain:8090/confluence/rest/api/content/"
fetch(url, {
method: 'POST',
headers: {
'Content-Type': 'application/json',
mode: 'cors',
cache: 'no-cache',
credentials: 'same-origin',
},
data: {
'type': 'page',
'title': "New Page",
'ancestors': [{ 'id': 97059352 }], // parent page id
'space': { 'key': "EXAMPLE_SPACE" },
'body': {
'storage': {
'value': "<h1>New Page!</h1>",
'representation': 'storage',
}
},
}
})
.then(response => console.log(response))
.catch(err => console.log(err.message))
}
EDIT: Now it's a 500 error, no longer that original error
Thanks for the reply.
I tried adding those headers, but still no luck. I did just realize that I probably need to pass an Authorization header in the format, which I just did, but still not working.
I tried submitting the requests with certain headers commented out as well with different combinations, but still nothings working.
I was referring to this tutorial for which headers to pass: https://pretagteam.com/question/create-a-confluence-page-using-python-api
function createPage() {
let url = "http://exampledomain:8090/confluence/rest/api/content/"
fetch(url, {
method: 'POST',
headers: {
'Authorization': 'Basic USER:PASS',
'Content-Type': 'application/json',
'Accept' 'application/json',
'User-Agent': 'x',
// mode: 'cors',
// cache: 'no-cache',
// credentials: 'same-origin',
},
data: {
'type': 'page',
'title': "New Page",
'ancestors': [{ 'id': 97059352 }], // parent page id
'space': { 'key': "EXAMPLE_SPACE" },
'body': {
'storage': {
'value': "<h1>New Page!</h1>",
'representation': 'storage',
}
},
}
})
.then(response => console.log(response))
.catch(err => console.log(err.message))
}
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
The authorization header will not work like that, because you need to encrypt.
Try this link.
I recommend to use a browser REST extension, to build and test your POST rest call, first. If it works, then you can more or less "Copy & Paste" to python.
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.