Hi,
I am trying to create a new page under a space using the following code in nodejs:
var jsondata = { "type": "page", "title": "My Test Page", "space": { "key": "TEST" }, "body": { "wiki": { "value": "h1. Hello world!", "representation": "wiki" } }};
router.get('/content', (req, res) => {
axios.post(`${confluenceRootUri}/rest/api/content`, {
headers: {
'Content-Type': 'application/json; charset=utf-8',
"Authorization": "Basic " + Buffer.from(username + ":" + password).toString('base64')
},
data: JSON.stringify(jsondata)
})
.then(response => {
res.send(response.data);
})
.catch(error => {
res.status(error.status || 500);
res.send(error.response.data);
});
}
However I am getting the following bad request:
{
statusCode: 400,
data: {
authorized: true,
valid: false,
allowedInReadOnlyMode: true,
errors: [
{
message: {
key: "type is required to create content",
args: [ ]
}
}
],
successful: false
},
message: "Could not create content with type null",
reason: "Bad Request"
}
I also have tried the example from the website in python but it gives me syntax error
curl -u admin:admin -X POST -H 'Content-Type: application/json' -d '{"type":"page","title":"new page",
"space":{"key":"TST"},"body":{"storage":{"value":"<p>This is <br/> a new page</p>","representation":
"storage"}}}' http://localhost:8080/confluence/rest/api/content/ | python -mjson.tool
What am I missing?
Okay, I found my problem, my axios request was in the wrong format, the corrected code is:
```
axios({
method: 'post',
url: `${confluenceRootUri}/rest/api/content`,
headers: {
'Content-Type': 'application/json; charset=utf-8',
"Authorization": "Basic " + Buffer.from(username + ":" + password).toString('base64')
},
data: jsondata
})
```
where to run this curl command ? do i need copy paste the whole command in cmd prompt ?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
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.