Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Create Confluence Page via REST API (Bad Request)

renatogbp May 23, 2019 edited

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?

1 answer

1 accepted

0 votes
Answer accepted
renatogbp May 24, 2019

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
})
```

Abhishek Kalamkar July 25, 2023

where to run this curl command ? do i need copy paste the whole command in cmd prompt ?

Suggest an answer

Log in or Sign up to answer
TAGS
atlassian, confluence, marketing templates, confluence templates, marketing project management, content strategy, campaign planning, marketing collaboration, confluence for marketers, atlassian learning, marketing workflows, confluence best practices

5 must-use templates for Marketing teams (from a Confluence Marketer!) 👩🏻‍🎨

Who doesn’t love a good template? We sure do! Check out our top template picks for Marketing teams who want to streamline their processes, enhance collaboration, and take their marketing to new heights.

Read more 📚
AUG Leaders

Atlassian Community Events