How to escape whitespace (and other special chars) when passing JQL in curl?

Hello,

I am trying to get issues from REST and having problems escaping special characters in command line.

For example, this works well (returns a valid JSON) through the browser:

https://flow-jira.ubs.net/rest/api/2/search?jql=project="Test Project"&sprint=201708R1&issue_type=Story,Maintenance

but when trying it through curl in command line--like this:

Curl -u user:password -X GET -H "Content-Type: application/json" https://jiraserver/rest/api/2/search?jql=project="Test Project"&sprint...

the JQL query breaks on special chars (space, &). I tried ="Test"%" "%"Project", "Test"\\%" "\\%"Project", and many other combinations of escape and concat characters and nothing works.

Any ideas?

Also, is there a better way to get issues from JIRA API as a batch job?

 

Thank you,

Alla

 

1 answer

0 vote

Hi Alla,

Do you run into this issue with any other commands that need the & symbol and what shell are you using?

To start off with, here is the curl command I used that was successful:

curl -u user:pass -X GET -H "Content-Type: application/json" http://localhost:8080/rest/api/2/search?jql=project="ATLAS"&sprint="ATLAS Sprint 1"

I ask about your shell because I am using zsh and part of the profile does not allow me to run this command.  If I try to run the command with my shell settings I get the following:

zsh: no matches found: http://localhost:8080/rest/api/2/search?jql=project=ATLAS

If you are using a different shell or have changed your shell profile I would check that first. 

Cheers,

Branden

I figured this.

Just needed to double-quote the whole URL:

Curl -u user:password -X GET -H "Content-Type: application/json" "https://jiraserver/rest/api/2/search?jql=project=Test Project&sprint..."

Now I am trying to figure out how to deal with the JSON response I am getting. I think I will need to use PowerShell but it may be above my head :) Also, it seems that curl is only getting 50 issues, not all of them. This seems to be a known bug.

Started a new thread (https://community.atlassian.com/t5/Jira-questions/Converting-JSON-output-to-csv/qaq-p/643792)

Thank you for responding though, Branden.

Cheers,

Alla

Suggest an answer

Log in or Sign up to answer
How to earn badges on the Atlassian Community

How to earn badges on the Atlassian Community

Badges are a great way to show off community activity, whether you’re a newbie or a Champion.

Learn more
Community showcase
Published yesterday in Jira Software

How large do you think Jira Software can grow?

Hi Atlassian Community! My name is Shana, and I’m on the Jira Software team. One of the many reasons this Community exists is to connect you to others on similar product journeys or with comparabl...

365 views 4 10
Read article

Atlassian User Groups

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

Find a group

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

Find my local user group

Unfortunately there are no AUG chapters near you at the moment.

Start an AUG

You're one step closer to meeting fellow Atlassian users at your local meet up. Learn more about AUGs

Groups near you