I am using an HTML macro to in the confluence which allows you to write custom JavaScript code. I am trying to create a page using the javascript, for some reason I am getting a 415 Unsupported Media type error. I have specified the content-type as well in the code but still getting the same error.
here is the code that I am using
var myHeaders = new Headers();
myHeaders.append("Authorization", "Basic <api-token>");
myHeaders.append("Content-Type", "application/json");
myHeaders.append("Cookie", "atlassian.xsrf.token=784d27c2-5489-4932-b2e8-4123214f8ee2_41e5feab5ed210639dd428dae1bcd44e6df73e1c_lin");
var raw = JSON.stringify({
"spaceId": 395018479,
"status": "current",
"title": "API Test2",
"body": {
"representation": "Storage",
"value": "<h1>test</h1>"
}
});
var requestOptions = {
method: 'POST',
headers: myHeaders,
mode: 'no-cors',
body: raw,
redirect: 'follow'
};
fetch("https://my-site.atlassian.net/wiki/api/v2/pages", requestOptions)
.then(response => response.text())
.then(result => console.log(result))
.catch(error => console.log('error', error));
Thank you.