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 examples
https://developer.atlassian.com/cloud/jira/platform/rest/v3/intro/
I took a look in https://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("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 always 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 I am doing wrong?
CodePudding user response:
I create the request in a plain js request.js and then with "node request.js" I get a response properly. With a script definition in the html was not possible.