I am trying to get the issues list from JIRA by using the following POST request in nodejs.
Issues exist in JIRA, but the REST API response shows no results. Am I missing anything here to add/configure on JIRA?
Here is the code:
var request = require('request');
var bodyData = `{
"expand": [
"names",
"schema",
"operations"
],
"jql": "order by lastViewed DESC",
"maxResults": 10,
"fieldsByKeys": false,
"fields": [
"summary",
"status",
"assignee"
],
"startAt": 0
}`;
var authToken = Buffer.from("<EMAIL_ID>:<API_TOKEN>").toString('base64');
var options = {
method: 'POST',
url: 'https://<CUSTOM_SITE>.atlassian.net/rest/api/3/search',
authorization : 'Basic ' + authToken,
headers: {
'Content-Type': 'application/json'
},
body: bodyData
};
request(options, function (error, response, body) {
if (error) throw new Error(error);
console.log(
'Response: ' + response.statusCode + ' ' + response.statusMessage
);
console.log(options);
console.log(body);
});
API Response is:
{"startAt":0,"maxResults":10,"total":0,"issues":[]}
Hi @Yuvaraj M
You need to change
method: 'POST',
to
method: 'GET',
You're "getting" data out of Jira, so you can't use POST. POST is used when you create an issue
@WarrenThanks. Initially, I tried using "GET" method, but it did not work. So, I switched the request to "POST" as provided in the JIRA documentation for submitting the search parameters - an alternative to "GET" method.
One thing I just happen to notice on the API token page is the status of token shows that it was never accessed. Does it mean that the authentication did not happen even when the authorization info was sent in the request header?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi @Yuvaraj M
Yes, if the token is showing as never having been accessed, it means that you're having authentication problems. I'm in discussions in another thread with someone else who is having the same problem.
You should try using Postman (either the web based app or download it), because this will help you to get your authentication sorted and it has nothing to do with your code. Once you have it working in Postman, you can apply those changes to your code.
Also, I still say that POST is not an alternative to GET, they are for completely different functions and you won't successfully get any details back using it.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
@WarrenThank you. I have located the defect on my code after a few tries on the Postman tool. I am able to get the results now. The fix is place the authorization key inside the headers:
headers: {
authorization : 'Basic ' + authToken,
'Content-Type': 'application/json'
}
The documentation on the JIRA REST API for Node.js is misleading where the authorization key is placed outside the headers - https://developer.atlassian.com/cloud/jira/platform/rest/v3/#api-rest-api-3-search-get
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.