It's not the same without you

Join the community to find out what other Atlassian users are discussing, debating and creating.

Atlassian Community Hero Image Collage

Cloud Rest Call is not working For Issue Search.

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
DPK J Community Leader Nov 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.

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 .

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

0 votes
Warren Community Leader Nov 18, 2019

Hi @Chakresh Tiwari 

Totally agree with what @DPK J 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?

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

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

Warren Community Leader Nov 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

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 Community Leader Nov 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?

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

Warren Community Leader Nov 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

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

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

Warren Community Leader Nov 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

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. 

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. 

Suggest an answer

Log in or Sign up to answer
TAGS

Community Events

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

Find an event

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

Unfortunately there are no Community Events near you at the moment.

Host an event

You're one step closer to meeting fellow Atlassian users at your local event. Learn more about Community Events

Events near you