I'm writing a JavaScript app that generates a report across all out projects for my team. One of the roadblocks I'm facing is CORS when querying the JIRA REST API.
One workaround I'm currently trying is that I set up a node.js server that gets a proper session using my credentials and then tries to get all projects (via /rest/api/latest/project/).
The node.js app retrieves a proper session id. However, when it tries to query for all projects, the answer is always empty (as if it failed to authenticate properly).
This is the raw response, I marked some sensitive information with Xs:
{data: [ ], status: 200, statusText: "OK", headers: {server: "nginx", date: "Mon, 04 Apr 2016 22:58:24 GMT", content-type: "application/json;charset=UTF-8", transfer-encoding: "chunked", connection: "close", vary: "Accept-Encoding", x-arequestid: "58x134005x1", x-asessionid: "gbbla4", x-asen: "SEN-3321953", x-ausername: "anonymous", x-atenant-id: "XXXXX.atlassian.net", cache-control: "no-cache, no-store, no-transform", x-content-type-options: "nosniff", set-cookie: ["atlassian.xsrf.token=BJY0-9ZH5-270Y-1S6C|449aa35483219b58564XXXXXXXXXXXXXXXXXXX|lout; Path=/; Secure" ], strict-transport-security: "max-age=315360000;includeSubDomains" }, config: {transformRequest: { }, transformResponse: { }, headers: {Accept: "application/json, text/plain, */*", cookie: "JSESSIONID=XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX", Content-Type: "application/json", User-Agent: "axios/0.9.1" }, timeout: 0, xsrfCookieName: "XSRF-TOKEN", xsrfHeaderName: "X-XSRF-TOKEN", method: "get", url: "https://XXXXXXX.atlassian.net/rest/api/latest/project" } }
What confuses me the most is that x-ausername is anonymous, even though I appear to be properly authenticated. That's probably why the project list is empty (because I cannot see them).
But why is that? When I call the URL in my browser the JSON is returned just fine.
I'd be very grateful for insights on how to get this running. I already spent way more time on this than I wanted.
Thanks in advance,
Fred
Hi Fred,
Try to use /rest/api/2/project instead of /rest/api/latest/project.
In case this won't help. Check the authorization method. It seems that you're not authenticated properly. Do you use JWT as the authentication mechanism?
Hi Aleks,
thanks or the quick reply. I changed the URL but that didn't help. No, I'm not using JWT since this is not an add-on. I thought it would not be necessary to go that deep just to query our projects. Is JWT really necessary for that kind of interaction?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Same poblem using .NET and WebRequest.
Response come with ContentLength: -1 and HttpStatusCode: 200 (OK).
https://my.jira.domain/rest/api/2/search?jql=%20project=%22MY%22%20AND%20issuetype=%22epic%22
Same request in Chrome returns a normal data.
Request have worked a several days ago.
Requests without jql works fine: https://my.jira.domain/rest/api/2/project/10001
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.