0

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?

Aviya Oren
  • 19
  • 4

1 Answers1

0

It's a serverside problem and not a vue-js/clientside problem:

the cross-origin error means that your vue-application runs at a different domain than your jira webserver (e.g. example.org and jira.com). In the jira-webserver you have to set "cross-origin: *"

user3606183
  • 157
  • 9
  • but I am able to run this request using postman and get a 200 with the proper answer. so what is the difference? – Aviya Oren Nov 27 '18 at 07:59
  • cross-origin-domain is a security-browser feature. Outside the browser everything is possible....besides [postman doesn't care about CORS](https://stackoverflow.com/questions/36250615/cors-with-postman) – user3606183 Nov 27 '18 at 14:55
  • @AviyaOren would you mark my answer as the correct one or do you have any questions? – user3606183 Nov 04 '19 at 21:46