Cloud Rest Call is not working For Issue Search.

Chakresh Tiwari November 18, 2019

cloud Rest call for getting data by passing JQL as Parameter. But Every time it is returning 400 status Code which means invalid JQL But I tried JQL in Jira where it is returning Correct Response. I tried Resttemplate For Client.

/rest/api/3/search

2 answers

0 votes
Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2019

Hi @Chakresh Tiwari 

Totally agree with what @DPKJ has said above - it would be useful to see the JQL query (anonymised if required). Does the API call work for you without passing in a JQL at all? i.e does 

/rest/api/3/search

work or return an error?

Chakresh Tiwari November 18, 2019

I am Passing Correct JQl which is working on Jira but while doing that through api that is not working.

. like this

assignee = admin

and

project =Demo

Chakresh Tiwari November 18, 2019

Without passing JQL it is returning response but with JQL it has error.

Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 18, 2019

Hi @Chakresh Tiwari 

Okay, that's good news (sort of) because it means everything is working apart from the JQL. 

I may be wrong but I think you're passing in the JQL incorrectly. It should be part of the API call, so it should look like this for your query

/rest/api/3/search?jql=assignee=admin and project=demo

whereas you seem to be passing the JQL in as a parameter

Like # people like this
Chakresh Tiwari November 19, 2019

https://acisplugin.atlassian.net/rest/api/3/search?jql=%20project%20%3DDemo  I am Passing this URL in api call But still same problem.

I tried this also https://acisplugin.atlassian.net/rest/api/3/search?jql=assignee%3Dadmin%20and%20project%3Ddemo 

But both of these URLs are working in a browser. and Giving proper response but in api it is not working. 

Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 19, 2019

So in the browser both of these API calls work successfully, but not via code? Do you get a 400 error for both?

Have you tried using Postman to check it?

Chakresh Tiwari November 20, 2019

Yes, I have Tried with postman also but the same status code 400. For both the same Response.

Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2019

Could you give a screenshot from Postman showing just the GET section, as below?

Screenshot_2.jpg

And then also the response from Postman

Chakresh Tiwari November 20, 2019

Okk Please Check this Screenshot--2019-11-20 (2).png

Chakresh Tiwari November 20, 2019

or only with JQl please look at this one--2019-11-20 (3).png

Warren
Rising Star
Rising Star
Rising Stars are recognized for providing high-quality answers to other users. Rising Stars receive a certificate of achievement and are on the path to becoming Community Leaders.
November 20, 2019

Please take a look at my screenshot, because your GET line seems to have many problems :

  • You have 2 sets of // 
  • You don't have a valid atlassian URL
  • issueCount isn't a valid API call

What is in the GET box should have this format :

https://companyname.atlassian.net/rest/api/3/apicall?jql=...

where companyname is replaced with the name used in your Jira URL, apicall is replaced by a valid call as per the documentation and a valid jql statement is used

Chakresh Tiwari November 20, 2019

Yes I have removed this /  and  this issueCount is just for invoking my rest call inside that where i am calling JIRA rest there i am Passing this URL https://acisplugin.atlassian.net/rest/api/3/search?jql=assignee%3Dadmin%20and%20project%3Ddemo  which is working correct in both places browser and postman. 

Chakresh Tiwari November 20, 2019

Hi I passed this in JQL jql=key=DEMO-1  but that becomes jql=key%253DDEMO-1

after code run. Can you help me to fix this  I tried every possible way but I think because my JQL is becoming incorrect because of these changes So any help to correct this. 

0 votes
DPKJ
Community Leader
Community Leader
Community Leaders are connectors, ambassadors, and mentors. On the online community, they serve as thought leaders, product experts, and moderators.
November 18, 2019

@Chakresh TiwariCan you please elaborate and share query you are trying to pass, because it seems error is in JQL you are passing or how you are passing it.

Chakresh Tiwari November 18, 2019

Hi  i am Using this rest api for getting IssueCount using Resttemplate. for every other api  i am getting a response but for only this i am getting 400 status code.

@GetMapping("issueCount")
public ResponseEntity<String> getIssueCount(@AuthenticationPrincipal AtlassianHostUser hostUser,@RequestParam("jql") String jql) {
AtlassianHost host= hostUser.getHost();
UriComponentsBuilder builder = UriComponentsBuilder.fromHttpUrl(host.getBaseUrl() + ConstantsInf.issueSearch)
.queryParam("jql",jql);
System.out.println("-------------- URL " + host.getBaseUrl() + ConstantsInf.issueSearch);
RestTemplate restTemplate = atlassianHostRestClients.authenticatedAsAddon();
ResponseEntity<String> responseEntity = restTemplate.getForEntity(builder.toUriString(), String.class);
atlassianHostRestClients.authenticatedAsAddon().getForObject(builder.toUriString(), String.class);
String responsetemp = responseEntity.getBody();
return ResponseEntity.ok(responsetemp);
}

 I passed correct Jql still it is giving error. like this

assignee = admin

and

project =Demo

Thanks For your reply .

Chakresh Tiwari November 18, 2019

without JQL it is returning response but with jql returning 400 where is my Jql Incorrect or some other problem??

Suggest an answer

Log in or Sign up to answer