URL rest api parameter with spaces

Urban picture Urban · Oct 9, 2017 · Viewed 8.4k times · Source

I am using the rest API of JIRA to retrieve issues while filtering on the project name and issue type.

When I try to use an API call like:

String url3 = "jiraURL/rest/api/2/search?jql=project=GB AND issuetype=Requirement&maxResults=1000";

It works!

But when I try:

  String url3 = jiraURL/rest/api/2/search?jql=project=GB AND issuetype=Product Risk&maxResults=1000";

I got HttpClientErrorException: 400. Meaning my URL is wrong. I think the error lies in the fact that there is a space between the two words that are the issuetype.

I already tried putting + instead of spaces but that doesn't work. My first call works perfectly. But I don't know how to solve the second call.

Answer

ericP picture ericP · Oct 9, 2017

Each parameter name and value should be URL encoded. They should then be joined with a separator (either '&' or ';'). Looking at

...?jql=project=GB AND issuetype=Product Risk&maxResults=1000

I'm not sure whether jql, project and issuetype are separate parameters or if the whole string is a value for jql. If the former, the spaces should be replaced with their URL-encoded form ("%20"):

...?jql=&project=GB%20AND%20issuetype=Product%20Risk&maxResults=1000

If the latter, the "="s should also be URL-encoded:

...?jql=project%3DGB%20AND%20issuetype%3DProduct%20Risk&maxResults=1000