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

java + rest + jql

I want to fetch based on jql query.

My code:

final URI jiraServerUri = new URI(Constants.JIRA_SEARCH_URL);
		final JiraRestClient restClient = new AsynchronousJiraRestClientFactory().createWithBasicHttpAuthentication(https://localhost:8080/jira/rest/api/latest/search, "xxx", "xxx"); // It throws 403

How do i fetch data acording to jql

jql = "reporter=somename";

2 answers


A example with JRJC 2.00-m25:




public class JiraRestClientExample2 {

public static void main(String[] args) {
final String jiraUser = "user";
final String jiraPassword = "pass";
final String jiraBaseURL = "http://localhost:8080";
URI jiraServerUri = null;
JiraRestClient client = null;
jiraServerUri = new URI(jiraBaseURL);
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
client = factory.createWithBasicHttpAuthentication(jiraServerUri, jiraUser, jiraPassword);
IssueRestClient issueClient = client.getIssueClient();
SearchRestClient searchClient = client.getSearchClient();

SearchResult result = searchClient.searchJql("reporter=somename").claim();

for(Issue issue : result.getIssues()){



}catch(Exception e){
try {
} catch (IOException e) {


I think Azhar already has all of that.  The problem is now that it does not return what is needed, the client is converting the (desired) JQL to an unwanted format.

0 votes

There's some docs on the REST API, but I find the examples in there a better starting point than the basic docs.  Have a look at - it tells you how to form a number of query strings for use with the REST API

Hi Nic,

Thank you for your response. Finally my authentication is working. But the problem is i have too much code written already using http client which gives me data in json format. So i want the same using rest + java. I want Json result when i hit the query. Currently it gives me the whole list of scrips etc. Its is not in json format.

Can you please help me how to retrieve in json format. Thanks in advance.

Promise<SearchResult> searchJqlPromise = restClient.getSearchClient().searchJql(SRE_QUERY);
            for (Issue issue : searchJqlPromise.claim().getIssues()) {
                System.out.println(issue); //It doesnt gives the output in json format. Can i know how do i get in that format

Ok, you should dump whatever your "restClient" class is because it's reformatting valid json for you.

JIRA responds to REST calls with json data.  Just use it directly instead of using whatever that client is.

Hi Nic,

It doesnt give me json data. It gives only some random object

final JiraRestClientFactory  factory = new AsynchronousJiraRestClientFactory();
		final JiraRestClient restClient = factory.createWithBasicHttpAuthentication(new URI(""+SRE_QUERY)
System.out.println("========="+restClient); // it prints

Ah, my last comment was unclear, sorry.

When you make a REST call to JIRA, you get JSON back from it.  The problem you are having here is your rest client code  is  reformatting the json that JIRA gives to it.

Stop using the rest client, and use a simple plain REST call directly to JIRA.  That will give you json to work with.

How do i do that is there any example?

You should use whatever REST call/library your chosen language supports.

Suggest an answer

Log in or Sign up to answer
This widget could not be displayed.
This widget could not be displayed.
Community showcase
Published yesterday in Off-topic

Teams behind the teams - Your nominations please!

Teams do amazing things together. We’ve talked about the myth of the lone genius and how everything is actually the result of teamwork. You might be thinking, What about a novelist writing, say, Th...

58 views 0 7
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