Problem converting JQL to API calls

Ron Barak March 20, 2023

I'm having problems constructing Jira queries using the Jira API.

For instance, if I use the following query from Jira: 

project=onsip AND status in (Tabled) AND "Shortcut ID[Number]" = "10368" order by created DESC
I get a single result: https://oomacorp.atlassian.net/browse/ONSIP-521

However, when I try to run
https://oomacorp.atlassian.net/rest/api/3/search?jql=project=onsip&status=Tabled&Shortcut ID[Number]=10368
from the API, or
https://oomacorp.atlassian.net/rest/api/3/search?jql=project=onsip&status=Tabled&Shortcut%20ID[Number]=10368
from a browser, I get other results.

Can you tell me what is wrong with my syntax to the API/browser?

3 answers

1 accepted

0 votes
Answer accepted
Ron Barak March 21, 2023


Thanks, Bill.
Indeed, when I use the below, I get the expected results:

 "10368" order by created DESC
project = "onsip"
#status = "Tabled"
status = '(Tabled, "Tier 4 Accepted")'
shortcut_id = "10368"
"""
query_string = {
"jql": 'project=ONSIP AND status in (Tabled, "Tier 4 Accepted") AND "Shortcut ID[Number]"="10368" order by created DESC'
}
"""
query_string = {
"jql": 'project={project} AND status in {status} AND "Shortcut ID[Number]"="{shortcut_id}" order by created DESC'.format(project=project,status=status,shortcut_id=shortcut_id)
}
0 votes
Prince Nyeche
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.
March 20, 2023

You can URL encode the JQL string, that would be the approach to take. So this

project=onsip AND status in (Tabled) AND "Shortcut ID[Number]" = "10368" order by created DESC

becomes 

project%3Donsip%20AND%20status%20in%20%28Tabled%29%20AND%20%22Shortcut%20ID%5BNumber%5D%22%20%3D%20%2210368%22%20order%20by%20created%20DESC

Using google, there are free online URL encoders out there.

0 votes
Bill Sheboy
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.
March 20, 2023

Hi @Ron Barak 

It appears you have changed your JQL to substitute ampersands (&) for the AND operator, which is not going to work.

I recommend either replacing these manually with %20AND%20 to escape the spaces around the operator, or run your query from advanced issue search, and then grab the well-formed query from the browser address bar.

Kind regards,
Bill

Suggest an answer

Log in or Sign up to answer
DEPLOYMENT TYPE
CLOUD
PRODUCT PLAN
STANDARD
TAGS
AUG Leaders

Atlassian Community Events