3

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.

Mohit Tyagi
  • 2,788
  • 4
  • 17
  • 29
Urban
  • 585
  • 2
  • 13
  • 28

2 Answers2

3

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
ericP
  • 1,675
  • 19
  • 21
  • the query begins after jql= – Urban Oct 09 '17 at 11:11
  • I think you're saying that the `jql` parameter should be (an encoded form of) "project=GB AND issuetype=Product Risk". You would then want the latter. – ericP Oct 09 '17 at 11:15
  • That's probably a problem elsewhere. If you paste `jiraURL/rest/api/2/search?jql=project%3DGB%20AND%20issuetype%3DProduct%20Risk&maxResults=1000` into the input on [freeformatter.com](https://www.freeformatter.com/url-parser-query-string-splitter.html), you'll see that `jql` = "project=GB AND issuetype=Product Risk" – ericP Oct 09 '17 at 11:24
  • But that is kinda weird. Why is my first api call with spaces working perfectly? – Urban Oct 09 '17 at 11:26
  • You should compare both with the freeformatter.com interface. – ericP Oct 09 '17 at 11:32
1

Can you please try?

 try {
        String url3 = URLEncoder.encode("jiraURL/rest/api/2/search?jql=project=GB AND issuetype=Product Risk&maxResults=1000", "UTF-8");
    } catch (UnsupportedEncodingException e) {
        e.printStackTrace();
    }
Berkay Tutal
  • 119
  • 8