Using curl for lira API with a period in the fixVersion jql

437 Views Asked by At

I've tried various iterations of using either ", ' and ` to enclose a curl query to an instance of jira in order to get all issues for a particular fix Version.

curl -D- -u username:password -X POST -H "Content-Type: application/json" -d '{"jql":"project = PROJ AND fixVersion=Version-1.2.3"}' "https://thejirainstall.com/jira/rest/api/2/search"

However, using this and a couple of other change on fixVersion such as:

fixVersion="Version-1.2.3"

or

fixVersion=\"Version-1.2.3\"

or

fixVersion=Version-1\u002e2\u002e3

Add and remove quotes at will.

The ones that don't fail outright return:

{"errorMessages":["Error in the JQL Query: '\\.' is an illegal JQL escape sequence. The valid escape sequences are \\', \\\", \\t, \\n, \\r, \\\\, '\\ ' and \\uXXXX. (line 1, character 38)"],"errors":{}}

How do I either escape periods . or add another set of quotes?

1

There are 1 best solutions below

0
On BEST ANSWER

Ok, so it turns out that Jira doesn't permit version names in jql syntax. The version id must be used instead.

And, in order to get the version id you must parse the result from https://thejirainstall.com/jira/rest/api/2/project/ON/versions?

This now means that I have to use a JSON parser anyway. So, now I'm using jq via homebrew install jq

My current solution is to write a bash script as below:

JIRA_FIXVERSION
fixVersionQuery='https://thejirainstall.com/jira/rest/api/2/project/ON/versions?';
myJSONResponse=`curl -u username:password -X GET -H "Content-Type: application/json" --insecure --silent $fixVersionQuery |jq '.[] | {id,name} | select(.name=="Version-1.2.3" | .["id"]'`; 
echo $myJSONResponse;