Can anyone connect to this API, using Javascript: https://XXX.jira.com/rest/tempo-timesheets/3/worklogs/?dateFrom=2018-04-01&dateTo=2018-04-02 (change XXX with your URL prefix)?
I get error status 405.
And, even though I'm using a GET method, inspecting the page shows that it recognises the Request Method as OPTIONS.
My code works with this API: 'https://ghibliapi.herokuapp.com/films', for example. No authorisation needed. So the code isn't the problem.
Also, someone else has tried the same Jira API that doesn't work for me in another js script using `fetch`, instead of `XMLHttpRequest`, and that didn't work either.
This is my the javascript code that tries to connect with the API:
index.html:
<!DOCTYPE html><html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>App</title>
</head>
<body>
<div id="root"></div>
<script src="scripts.js"></script>
</body>
</html>
scripts.js:
const app = document.getElementById('root');
const container = document.createElement('div');
container.setAttribute('class', 'container');
app.appendChild(container);
var request = new XMLHttpRequest();
var baseURL = 'https://xxx.jira.com'; // replace xxx with your (company's) URL
request.open('GET', baseURL + '/rest/tempo-timesheets/3/worklogs/?dateFrom=2018-04-01&dateTo=2018-04-30&teamId=32', true); //you can change or delete the teamId or dates, I just added them so the results wouldn't be very big
request.withCredentials = true;
request.setRequestHeader("Access-Control-Allow-Headers", "Authorization");
request.setRequestHeader("Authorization", "Basic XXX"); //replace XXX with <your-admin-username>:<your-password> in Base64
request.send();
request.onload = function ()
{
alert("I checked and this alert doesn't work, so request.onload doesn't even get called");
var data = JSON.parse(this.response);
if (request.status >= 200 && request.status < 400)
{
data.forEach(item =>
{
const card = document.createElement('div');
card.setAttribute('class', 'card');
const h1 = document.createElement('h1');
h1.textContent = item.id;
const p = document.createElement('p');
item.id = item.id.substring(0, 4);
p.textContent = `${item.id}...`;
container.appendChild(card);
card.appendChild(h1);
card.appendChild(p); });
}
else
{
const errorMessage = document.createElement('marquee');
errorMessage.textContent = `Not working`;
app.appendChild(errorMessage);
}
}
alert("This alert does work");
Another weird issue is that the same Jira API, with the same authentification works in Postman and in a script in Google Apps Script.
Note, that I'm opening the index file in Chrome and using a CORS plugin that ususally works.
I've also tried all these Request Headers and more:
request.setRequestHeader("X-Atlassian-Token", "nocheck");
request.setRequestHeader("X-AUSERNAME", "dana.zainescu");
request.setRequestHeader("Content-Type", "application/json");
request.setRequestHeader(":method:", "GET");
request.setRequestHeader("Access-Control-Allow-Origin", "*");
request.setRequestHeader("Access-Control-Allow-Credentials", "true");
request.setRequestHeader("Access-Control-Allow-Methods", "GET");
request.setRequestHeader("Access", "GET, OPTIONS");
request.setRequestHeader("Access-Control-Max-Age", 1000);
request.setRequestHeader("Data-Type", "json");
request.setRequestHeader("Connection", "keep-alive");