JQL query wrong results

Franklin Manubag September 9, 2019

I've created a curl script but it seems the query is showing wrong results.

curl -H "Authorization: Basic ZnJhbmtsaW4ubWFudWJhZ0BhY2MuY28ubno6WW5HQUFNdUJ4WmF0NDBUelVielUyRDAy" -X GET -H "Content-Type: application/json" "https://project.atlassian.net/rest/api/2/search?jql=project=NAME&status=done&runQuery=true"

1 answer

0 votes
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2019

The data part of parameter jql has to encoded ans jql does not take & in query, so if you JQL query is,

project=NAME AND status=done

it should be url encoded,

project%3DNAME%20AND%20status%3Ddone

If you are not happy with encoding your query every time, try using POST request in place of GET request for JQL search, check this page ('Searching for issues examples' section)

https://developer.atlassian.com/server/jira/platform/jira-rest-api-examples/

Franklin Manubag September 9, 2019

Thanks.. that worked..

I'm facing another issue adding the fixVersion but the value has a space. The http link works on a browser but fails on curl.

curl -H "Authorization: Basic ZnJhbmtsaW4ubWFudWJhZ0BhY2MuY28ubno6WW5HQUFNdUJ4WmF0NDBUelVielUyRDAy" -X GET -H "Content-Type: application/json" "https://project.atlassian.net/rest/api/2/search?jql=status=done+and+project=NAME+and+fixVersion=%22AB%203.1%22"

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2019

This worked for me,

status%20%3D%20Done%20AND%20project%20%3D%20NAME%20AND%20fixVersion%20%3D%20%22AB%203.1%22

 Also I suggest you switch to POST request to search for issues via API, in that you can copy query directly from search field, no need for encoding etc.

Franklin Manubag September 9, 2019

I've used your suggestion and encountered this error.. I will test the POST

 

{"errorMessages":["Error in the JQL Query: Expecting operator before the end of the query. The valid operators are '=', '!=', '<', '>', '<=', '>=', '~', '!~', 'IN', 'NOT IN', 'IS' and 'IS NOT'."],"errors":{}}

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2019

@Franklin Manubagrequest type POST is best suited for this.

Also I think you are using Jira Cloud? If so switch to API version 3. https://developer.atlassian.com/cloud/jira/platform/rest/v3/

 

Franklin Manubag September 9, 2019

I've tried POST

 

curl -H "Authorization: Basic ZnJhbmtsaW4ubWFudWJhZ0BhY2MuY28ubno6WW5HQUFNdUJ4WmF0NDBUelVielUyRDAy" -X POST -H "Content-Type: application/json" --data '{"jql":"project = NAME","status=done", "fixVersion=AB 3.1","fields":["id","key"]}' "https://project.atlassian.net/rest/api/2/search"

 

and got an error

{"errorMessages":["Unexpected character (''' (code 39)): expected a valid value (number, String, array, object, 'true', 'false' or 'null')\n at [Source: org.apache.catalina.connector.CoyoteInputStream@159e59b8; line: 1, column: 2]"]}

DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
September 9, 2019

Try this,

curl --request POST \
--url 'https://project.atlassian.net/rest/api/3/search' \
--header 'Authorization: Basic ZnJhbmtsaW4ubWFudWJhZ0BhY2MuY28ubno6WW5HQUFNdUJ4WmF0NDBUelVielUyRDAy' \
--header 'Accept: application/json' \
--header 'Content-Type: application/json' \
--data '{
"jql": "status = done AND project = NAME AND fixVersion = \"AB 3.1\""
}'

Suggest an answer

Log in or Sign up to answer