Hello everyone,
I have a question reagrding how to call make a API call for JIRA Cloud API using Basic Authorization.I want to get my Issues and then edit some values through REST API.
I follow some tutorials and exampleshttps://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/I took a look inhttps://support.atlassian.com/user-management/docs/create-and-update-groups/I think I must give premissions in the as I read here https://developer.atlassian.com/cloud/jira/platform/oauth-2-3lo-apps/and for the basic authorization I shall get a api token here use the https://developer.atlassian.com/cloud/jira/platform/basic-auth-for-rest-apis/I use this code:
```<html><head></head><body><script>console.log("called function httpGetRequest");let url = 'https://my-domain.atlassian.net/rest/api/3/issue/TEST-2';let user = '<my email address>';let password = '<basic api token>';let pass_base64 = btoa(password);
let auth_buff = user+":"+password;let auth = btoa(auth_buff);
console.log ("auth : "+auth);
var xhr = new XMLHttpRequest();
xhr.open("GET", url);xhr.withCredentials = true;
xhr.setRequestHeader('Access-Control-Allow-Origin', "+");xhr.setRequestHeader("Authorization", "Basic " + auth);xhr.setRequestHeader('Accept', 'application/json');
xhr.onreadystatechange = function () {console.log( 'Response: '+ xhr.status + ' - '+xhr.responseText);if (xhr.readyState === 4) {console.log(xhr.status);console.log(xhr.responseText);}};
</script></body></html>```
I get allways the error:
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://my-domain.atlassian.net/rest/api/3/issue/TEST-2. (Reason: CORS header ‘Access-Control-Allow-Origin’ missing).
XHR GET https://my-domain.atlassian.net/rest/api/3/issue/TEST-2.
Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource at https://my-domain.atlassian.net/rest/api/3/issue/TEST-2. . (Reason: CORS request did not succeed).
What can I do?Best Regards,
Paul
Hi @P Mart ,
The code you have works in a browser. From a browser you can't call another domain, this is called a cross-origin request.
Your browser will block this request.
As an alternative, you could write your code in e.g. node, and run it from there.
It looks like you're new here. Sign in or register to get started.