Reputation: 662
I am trying to retrieve issues from jira. I am able to get response using username and password. But As passwords keeps changing, i want to authenticate using api token. But i am not able to do it. Here is my Code:
public class JiraMetrics {
private static final String JIRA_URL = "https://jira.company.com";
private static final String JIRA_USERNAME = "username";
private static final String JIRA_password = "password";
public static void main(String[] args) throws URISyntaxException {
JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
URI uri = new URI(JIRA_URL);
JiraRestClient client = factory.createWithBasicHttpAuthentication(uri,JIRA_USERNAME,JIRA_Password);
//Calling issues
Promise<SearchResult> searchJqlPromise = client.getSearchClient().searchJql("query");
for (Issue issue : searchJqlPromise.claim().getIssues()) {
System.out.println(issue.getKey());
}
}
Instead of password, could we just call using api token?
Upvotes: 2
Views: 5824
Reputation: 5541
I tried the suggested answer but that failed for me. I did get it to work using the suggestion on this page via an Authentication Handler that passes in the Bearer/Access Token: https://community.atlassian.com/t5/Jira-questions/How-do-I-use-a-personal-access-token-PAT-in-jira-rest-java/qaq-p/1859167
Upvotes: 0
Reputation: 101
You have to :
Upvotes: 1