Create
cancel
Showing results for 
Search instead for 
Did you mean: 
Sign up Log in

rest search returns mixed errors

Blair Johnston November 27, 2012

I'm just learning jira and the rest api so this is probably something quite simple, but I can't find my way around it.

I have a jql query which works fine when submitted via advanced search but returns various unexpected results when submitted via rest.

The objective of the query is to return all issues associated with a list of keys. The jql I use is:

"key in (proj-35. proj-36)" where PROJ would be the project key.

In advanced search this returns the two issues with the listed keys.

When I submit the following get request I get 152 issues, presumably all from the project.

/rest/api/2/search?key+in+%28proj-35%2Cproj-36%29&0&9999&id,key,summary,description,status&

When I submit a post request I get two diifferent responses depending on whether I use upper or lower case for the keys in the search. In both cases I get an 400 bad request response.

The post request is:

POST /rest/api/2/search HTTP/1.1

The json is (copied from the captured post):

{"jql":"key in (proj-35,proj-36)","startAt":0,"maxResults":9999,"fields":["id","key","summary","description","status"]}

I have tried with and without quotes on both the keys. This seems to make no difference.

When upper case keys are sent I get the message ""An issue with key 'PROJ-35' does not exist for field 'key'." repeated for each key submitted.

When I submit the keys in lower case the message I get is ""The issue key 'proj-35' for field 'key' is invalid." again repeated for each key submitted.

I also tried the following jql with identical results in both upper and lower case.

{"jql":"key='PROJ-35' || key='PROJ-36'","startAt":0,"maxResults":9999,"fields":["id","key","summary","description","status"]}

The array of repsonses to what, to the best I can find are functionally identical queries, is baffling. Especially the "invalid key" one.

Any help or suggestions would be greatly appreciated.

Thanks,

Blair


1 answer

1 accepted

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Answer accepted
Faisal
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.
November 27, 2012

Hi Blair,

I did a quick test on this, and I managed to perform a search via REST by running the following request:

curl -u admin:admin http://afaisal-pc:8080/jira/rest/api/2/search?jql=project=MP+AND+assignee=admin

Hence to apply this to your JQL search, perhaps you may try to run the following URL:

/rest/api/2/search?jql=issuekey+in+"(MP-1,MP-2)"

I hope that this will help.

Cheers

Blair Johnston November 27, 2012

Ahmad, thanks for responding.

I'm obviously a bit rusty on my web programming...I interpreted the parameters in the Get reference for search as positional parameters rather than named, so I just put in the jql itself rather than jql=....

When I changed to match your suggestion the get request worked. But as my issue list is arbitrarily long so I need this to to work in a post request. Following your example, I changed "key" to "issuekey" but that turned out not to make any difference.

I finally traced the post problem to my use of .net's Request object. For get requests the request is not sent until I ask for the response, however with post requests it is sent as soon as I start writing the post data. My app is using a centralized send object which manages the session, cookies, common headers, etc. and I was writing the post data to the request object before calling this method, inadvertently sending the request before authentication. When I accounted for this properly, the call returned the expected results :-).

Thanks for your help!

TAGS
AUG Leaders

Atlassian Community Events