The Atlassian Community Forums are currently in read-only mode. We will be relaunching on a new platform on September 22 (read more here). We apologize for the extended downtime. For concerns or questions, please email communitymanagers@atlassian.com. See you on the other side, on the new Atlassian Community Forums! :)

×

Forums

Articles
Create
cancel
Showing results for 
Search instead for 
Did you mean: 

Connect to Jira using Java API and JQL

Bindiya Naik
I'm New Here
I'm New Here
Those new to the Atlassian Community have posted less than three times. Give them a warm welcome!
November 16, 2022

Here is my code below:

package com.java.BtBCode2;

import java.net.URI;

import com.atlassian.jira.rest.client.api.AuthenticationHandler;
import com.atlassian.jira.rest.client.api.JiraRestClient;
import com.atlassian.jira.rest.client.api.SearchRestClient;
import com.atlassian.jira.rest.client.api.domain.Issue;
import com.atlassian.jira.rest.client.api.domain.SearchResult;
import com.atlassian.jira.rest.client.auth.BasicHttpAuthenticationHandler;
import com.atlassian.jira.rest.client.internal.async.AsynchronousJiraRestClientFactory;
import com.atlassian.util.concurrent.Promise;

 

public class JiraIntegration {
static JiraRestClient restClient;
public static void main(String[] args) throws Exception {

URI jiraServerUri = URI.create("https://someurl/login.jsp");

AsynchronousJiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();

AuthenticationHandler auth = new BasicHttpAuthenticationHandler("HGFFGHHH", "pasword");
restClient = factory.create(jiraServerUri, auth);

// Any valid search filter(JQL)
String jql = "project = Sample UI and component = Sample UI";

int maxPerQuery = 100;
int startIndex = 0;

try {
SearchRestClient searchRestClient = restClient.getSearchClient();

while (true) {


Promise<SearchResult> searchResult = searchRestClient.searchJql(jql, maxPerQuery, startIndex, null);
//Promise<SearchResult> searchResult = searchRestClient.getProjectClient().getAllProjects().claim();
SearchResult results = searchResult.claim();

for (Issue issue : results.getIssues()) {
System.out.println(issue.getKey());
}

if (startIndex >= results.getTotal()) {
break;
}

startIndex += maxPerQuery;

System.out.println("Fetching from Index: " + startIndex);
}

} finally {
restClient.close();
}

}
}

 

After executing this line of <<"Promise<SearchResult> searchResult">> , the control comes directly to finally and I get error msg on console as below

Exception in thread "main" java.lang.NoSuchMethodError: com.atlassian.jira.rest.client.api.SearchRestClient.searchJql(Ljava/lang/String;)Lcom/atlassian/util/concurrent/Promise;
at com.java.BtBCode2.JiraIntegration.main(JiraIntegration.java:45

 

Can you please suggest what is going wrong?

1 answer

Comments for this post are closed

Community moderators have prevented the ability to post new answers.

Post a new question

0 votes
Tom Lister
Community Champion
November 17, 2022

Just a guess, I've not used the Jira Client APsI's

The searchJql method expects Integer objects for maxResults and startAt.

Have you tried creating the values as Integer rather than int?