Forums

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

I am getting 400 bad request from jira when trying to get list of issues via jira rest api

robera worku June 13, 2018

here is my rest client code

exports.jqlBuilder = function(project, issueType, label, fromDate, toDate, thisMonth) {
var baseUrl = "https://xxx.atlassian.net/rest/api/2/search?jql=";
var extend = "&fields=issuetype,priority,assignee,status,description,created,creator,reporter,duedate,summary,resolution,updated,resolutiondate&expand=changelog&startAt=";
if (thisMonth) {
var req = encodeURIComponent("project = ") + "'" + project + "'" + encodeURIComponent(" AND issuetype = ") + "'" + issueType + "'" + encodeURIComponent(" AND labels in (") + label + encodeURIComponent(") AND created >= startOfMonth() AND created <= endofMonth()");
var searchUrl = baseUrl + req + extend;
return fetchedIssues(searchUrl);
}

and here is the fetchedIssues function

function fetchedIssues(searchUrl) {
return new Promise(function(resolve, reject) { 
getIssues(searchUrl).then((result) => { resolve(result) });})}

and here is my getIssues function

function getIssues(url) {
return new Promise(function(resolve, reject) { issue(url, startAt).then(function(result) {*
***}/*not important*/

function issue(url, startIndex) {
return new Promise(function(resolve, reject) {
client.get(url + startIndex, function(data, response) {
if (response.statusCode !== 200) {
reject(new Error('Fail with the status code: ' + response.statusCode));}
resolve(data); }) })}

 

this code executes 2 times and works on the second. i dont know why though

 

here is the response i get

{ errorMessages:
[ 'Error in the JQL Query: Expecting either \'OR\' or \'AND\' but got \'Jun\'. (line 1, character 71)' ],
errors: {} }

1 answer

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
June 13, 2018

My concern is what happens in this JQL query when your labels have spaces in them?  I think that this could explain why you're seeing this specific JQL error.  You don't see that kind of error if your query is getting parsed correctly.   If I'm correct then I would expect that your Jira site has at least one label that looks like this 'May Jun' or '2018 Jun' (without quotes).

From looking at your syntax my fear is that we're not providing the URI encoding needed on the URL level to make this work.  Those label names can contain spaces, so the JQL should either use quotes before handle (single or double) or it would need to parse out labels with space values and convert them to a %20

Suggest an answer

Log in or Sign up to answer
TAGS
AUG Leaders

Atlassian Community Events