Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

REST API - Issue Search API returns no results

Yuvaraj M July 10, 2019

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":[]}

1 answer

1 accepted

0 votes
Answer accepted
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 10, 2019

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

Yuvaraj M July 10, 2019

@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?

Like Gazaliy Alade likes this
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
July 10, 2019

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.

Like Alton Michaux likes this
Yuvaraj M July 11, 2019

@WarrenOk. Let me give it a try using Postman.

Like Gazaliy Alade likes this
Yuvaraj M July 11, 2019

@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

Nodejs.PNG

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events