Accessing Jira API from javascript ajax call getting CORS error

Vasanth April 14, 2016

I have installed JIRA in my local machine and trying to use the REST API from another application which is installed in same machine.

While am calling the API from ajax call, I am getting the below CORS error.

Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at http://192.168.1.174:8080/rest/api/latest/issue/TESTPR-1. (Reason: CORS header 'Access-Control-Allow-Origin' missing).

Even I added the requesting URL in JIRA whitelist, but getting same error only.

2 answers

0 votes
Torsten Priebe July 14, 2016

I have the very same issue (trying to use Confluence Cloud REST API rather than JIRA). Any news on this?

0 votes
Aleks Yenin (Polontech)
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.
April 14, 2016

Hi,

Have you set up headers:

headers = {

'Access-Control-Allow-Origin':'*',
'Content-Type': 'application/json',
'X-Atlassian-Token': 'nocheck'
}

Are you working with iframes?

Is that JIRA cloud?

 

Vasanth April 14, 2016

Thanks for your reply Aleks. I added those headers, but still its not working.

Are you working with iframes? - NO (using simple ajax call)

Is that JIRA cloud? - NO (installed in my local machine. I tired with JIRA cloud as well, getting same error)

Vasanth April 18, 2016

Aleks,

This is my sample code,

<html>
<body>
    Test <button onclick="testJira();">Click</button>
    <script>
        function testJira() {
            $.ajax({
                type: "GET",
                crossDomain: true,
                dataType: "json",
                url: "http://192.168.1.174:8080/rest/api/latest/issue/TESTPR-1",
                headers: {
                    'Content-Type' : 'application/json',
                    'Authorization' : 'Basic something=',
                    'X-Atlassian-Token': 'no-check',
                    'Access-Control-Allow-Origin' : '*'
                },
                success: function(result) {
                  alert('success:::::'+JSON.stringify(result));
                },
                error: function(error) {
                  alert('error:::::'+JSON.stringify(error));
                }
            });
        }
    </script>
    <script src="https://code.jquery.com/jquery-1.12.0.min.js"></script>
</body>
</html>

Ajay Kere June 4, 2018

I have run same code but I got below error
"Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access."

 

please let me know How can I resolve this?

Suggest an answer

Log in or Sign up to answer