Has the Rest API changed for JIRA? I'm unable to query a project by status

Chris Voisey November 27, 2017

Until recently, the following command would work:
curl -D- -u "email:password" -X GET -H "Content-Type: application/json"  https://mydomain.atlassian.net/rest/api/2/search?jql=project%20%3D%20TTI%20AND%20status%20in%20('In Progress','Build Broken','Unscheduled','Ready for Development', 'In Review', 'Requirements Definition')%20ORDER%20BY%20priority%20DESC

Now when I run this, I am getting:
syntax error near unexpected token `('

So what has changed?  The problem is obviously with the parenthesis, but this used to work.  I've even tried changing it to a %28, but that makes things worse.  

 

1 answer

0 votes
Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 28, 2017

I'm not sure what would have changed recently.  So I walked through this same set of commands in my Cloud instance and using your syntax I was able to reproduce this same problem.   I then went back to a few of the examples from our developer REST API Tutorials.

In looking at these I noticed that your URL string was note in single quotes like the examples in that tutorial were.

So I think you can change your curl request to look like this:

curl -D- -u "email:password" -X GET -H "Content-Type: application/json"  'https://mydomain.atlassian.net/rest/api/2/search?jql=project%20%3D%20TTI%20AND%20status%20in%20('In Progress','Build Broken','Unscheduled','Ready for Development', 'In Review', 'Requirements Definition')%20ORDER%20BY%20priority%20DESC'

When I did this, I was able to get back search results in my test, even when the URL had () or not.

Cheers,
Andy

Chris Voisey November 29, 2017

I think we are close, however when you run this full query, with the single quotes within the single quotes, it tries to run each of those single quote items too.  i.e., after the first result, you get:

curl: (6) Could not resolve host: Progress,Build

curl: (6) Could not resolve host: Broken,Unscheduled,Ready

... and so on.

I'm very curious to what changed though.  This worked great, untouched for a month or so now.  All the sudden I get these errors.

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 29, 2017

Hi Chris,

Sorry about that, I didn't think about the single quotes in the JQL itself.  For that reason, it's probably better to use the double quotes to encapsulate the entire URL like this:

curl -D- -u "email:password" -X GET -H "Content-Type: application/json"  "https://mydomain.atlassian.net/rest/api/2/search?jql=project%20%3D%20TTI%20AND%20status%20in%20('In Progress','Build Broken','Unscheduled','Ready for Development', 'In Review', 'Requirements Definition')%20ORDER%20BY%20priority%20DESC"

Try this,
Andy

Chris Voisey November 29, 2017

Thanks for the continued persistence through this one!!  I wish it was that simple.  I already (and again right now) tried that and it still doesn't work.

I get a 400 error.

To simplify this even further ... just to remove any noise, I used this smaller version with the same error:
curl -D- -u "email:password" -X GET -H "Content-Type: application/json"  "https://mydomain.atlassian.net/rest/api/2/search?jql=project%20%3D%20TTI%20AND%20status%20in%20('In Progress')"

(Don't worry, I'm also putting in my correct domain and password info)  :)  Actually, if I remove the "AND status in ('In Progress')" the query will work.  LIkewise, I also tried this with real spaces, removing the special character codes.  Still the same thing.  After all, it is just a string at this point.

Two weeks ago all of this worked.  It is so odd.  

Andy Heinzer
Atlassian Team
Atlassian Team members are employees working across the company in a wide variety of roles.
November 29, 2017

Hi Chris,

I can call that REST API endpoint successfully when using the full URL inside double quotes.   So it is not clear to me why your instance would generate a 400 bad request error here still.  I was able to do this repeatedly with my Jira Cloud test instances using the steps I posted above.

I went back the  developer REST API Tutorials  and found another example that looks to be doing searches a bit differently.

From one such example:

Query using POST

If the JQL query is too large to specify in a URL parameter, you should POST your JQL query (in JSON format) to the REST API 'search' resource instead. Any additional URL parameters (to url) described above, should be included in your JSON-formatted JQL query.

 

curl -D- \
  -u admin:admin \
  -X POST \
  -H "Content-Type: application/json" \
  --data '{"jql":"project = QA","startAt":0,"maxResults":2,"fields":["id","key"]}' \
  "http://kelpie9:8081/rest/api/2/search"

I am curious if perhaps you can use this POST call instead of the GET.   When using this POST to search you have to use the '--data' parameter to specify the jql query in a json format as a means to make this query via REST.  

Perhaps the number of characters you have in your full URL when making this query is hitting up against some other limit that might exist in regards to either Jira or possibly a proxy/load balancer that might not be able to parse out very long URL requests.   I don't know of any such limit on Cloud, but try this. And then let me know the number of characters you have in total for example URL.

Chris Voisey November 29, 2017

Ya, I thought of this, however we are trying to adapt to a pre-made app and if we had to make this change it would be probably 35+ hours.  If we could even do it all.  We are stuck on the GET for now.

Chris Voisey November 29, 2017

Note that the problem is putting the status in there, technically with multiple values.  I just simplified the last code share to illustrate that it doesn't work and make it easier to repeat.  

Again, the odd thing is that it was all working fine.  It's very frustrating.  

Suggest an answer

Log in or Sign up to answer