Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

JIRA REST API: Cannot authenticate (CORS / media type error)

Bart Roelofs October 13, 2016

Hi developers,

I am struggling with this for days now. And I have no idea what to try anymore. 

I am making trying to get data from JIRA. But therefor I have to authenticate myself (obviously). But when I do, i get 2 errors:

  • The error I receive from the ajax request: 415 Unsupported Media Type
  • Another error in the console: XMLHttpRequest cannot load https://[myJira]/rest/auth/1/session/. No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://subdomain.mydomain.nl' is therefore not allowed access. The response had HTTP status code 415.

 

I have whitelisted my domainname in JIRA as the following:

http://subdomain.mydomain.nl/*

and checked the checkbox that is is allowed to collect / send data.

 

This is the request I am sending using my application:

 

var data = {
    'username': '[myUsername]',
    'password': '[myPassword]'
  };
  $.post('https://[myJira]/rest/auth/1/session/', data, {
      dataType: 'json',
      headers: {
          'ContentType': 'application/json; charset=utf-8',
      },
      type: 'POST',
      crossDomain: true,
      success: function(data) {
          console.log(data);
 	  }
});

Is there anyone who can tell me how to get rid of the errors and receive the data I need for my application?

Thank you!

Kind regards,
B. Roelofs

2 answers

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Dario B
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 15, 2017

Maybe not needed anymore, but as a work-around for Cloud you can use:

 

I hope this helps.

0 votes
Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 13, 2016

Hi Bart,

I guess you need to remove "dataType: 'json',". It expects plain post data rather than json.

Also you can authenticate your requests via BASIC AUTH headers. More info: https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials/jira-rest-api-example-basic-authentication

Bart Roelofs October 13, 2016

Hi Volodymyr, 

Thanks for your response! I am getting a 200 succes message back.

But the ajax still fails, due the Access-Control-Allow-Origin error. Any idea where to look? The white-list looks fine to me. But no idea what else it could be.

Kind regards,
Bart Roelofs 

Volodymyr Krupach
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
October 13, 2016

I assume that your JS is run form other domain than your JIRA. Try to add the domain to JIRA white-list: https://confluence.atlassian.com/adminjiraserver071/configuring-the-whitelist-802593145.html

Paul Calinawan May 22, 2017

I'm not seeing the whitelist configuration based on the link you gave. I'm already a site admin on my confluence site. Is there a special type of role to enable the whitelist configuration? Thanks.

Soulxy Thank December 4, 2017

@Volodymyr Krupach @Bart Roelofs

I add whitelist  of my domain, but there are still 415.

$http.post(url, userObj, {
headers: {
'Content-Type': 'application/json'
}
})
TAGS
AUG Leaders

Atlassian Community Events