I have been trying to use the JIRA rest API using vue js application, after generating the API key I have used postman to run a API request and it work perfectly.
First I have tried using the axios client but then I was stuck with cross origin because the request is 'Option' and not 'Get'.
That was the code:
axios.get(session_url, {
headers: {'Authorization': + basicAuth }
}).then(function(response) {
console.log('Authenticated');
}).catch(function(error) {
console.log('Error on Authentication');
});
Then I wanted to try a different solution and installed jquery. used this code:
$.ajax({
url: session_url,
async: true,
type:'GET',
dataType: 'json',
contentType: 'application/json',
beforeSend: function(xhr) {
xhr.setRequestHeader("Authorization", "Basic "+btoa(auth));
},
success: function(json){
alert('success');
},
error: function(err) {
console.log(err);
}
});
But this also didn't work, I found out when using data type: 'json' the request is OPTION and then get's cross origin problem . and when I'm using 'jsonp' the request gets a 400 response, when I'm looking over the request I don't see authentication request so I can edit the request and run it again and it's working.
What I am doing wrong ? how can I fix that?