It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

JQL query wrong results Edited

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

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/

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"

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.

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":{}}

@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/

 

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]"]}

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
Community showcase
Published in Jira

The add-in you’ve been waiting for: Jira Cloud for Excel 🙌

Introducing Jira Cloud for Excel Here at the product integrations team at Atlassian, we are thrilled to announce the new Jira Cloud for Excel add-in! This add-in lets you export Jira data directly ...

842 views 5 22
Read article

Community Events

Connect with like-minded Atlassian users at free events near you!

Find an event

Connect with like-minded Atlassian users at free events near you!

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you