I’m prototyping a Confluence macro for an internship and I need to make a call to the JIRA REST API from the .HBS file that’s rendered into view. I’ve tested out basic auth with curl to obtain the data I want with a GET request and that works but when I attempt to do the same from within the <script>
tags in my .HBS file with fetch()
the macro sends out an OPTIONS request instead without the header I set. Why is that and how do I fix this? My code is below:
let url = 'https://site.atlassian.net/rest/api/3/search'
let h = new Headers();
h.append('Accept', 'application/json');
//CjhuFx0J6eaocyKTz0OdF78F
let encoded = window.btoa('user@email.com:API TOKEN');
let auth = "Basic " + encoded;
h.append('Authorization', auth)
let req = new Request(url, {
method: 'GET',
headers: h
})
fetch(req)
.then( (res) => {
return res.json().then( (data) => {
if(res.ok) {
return data;
} else {
return Promise.reject({status: res.status, data});
}
});
})
.then((data) => {
console.log(data);
})