Export issues using JIRA's Java API


I have the opportunity to use JIRA's Java API and would like to introduce it.

There were a lot of documents and examples using Curl for REST API, but even if you search on the net for Java API, I found the following official JIRA tutorial, but it wasn't useful because the information was out of date.

Besides that, I found a sample of a strong man who analyzes JSON directly using HttpClient.

Reinventing the wheel, but exporting a summary of JIRA issues to Excel I have created a sample and would like to introduce it.

Introducing how to use JIRA's Java API.

An example is a Java program that outputs an overview of JIRA issues to MS Excel. It's already provided as a standard feature (*), but I hope it helps anyone who wants to learn JIRA's Java API. \ * Export JIRA search results to Microsoft Excel (https://ja.confluence.atlassian.com/jira063/exporting-search-results-to-microsoft-excel-683542534.html)

When executed with a Java batch program, the title, summary, and description are output to the Excel specified by the first argument. In addition, the code published on GitHub below is just an example, so the part that outputs Excel is not particularly sophisticated.

About the order of investigation and the points that I felt doubtful

I will write down the order and questions I checked below in chronological order. If you just want a conclusion, see the next section.

There should be a Java-wrapped API as well as a REST API.

→ There is an API. It is written at the end of the following page. I'm not sure which one to use, JIRA Server, Cloud, Software Server, Service Desk Server. https://developer.atlassian.com/jiradev/jira-apis

What should I use for the dependent library in the first place?

From a different point of view, I searched for a working sample because it could be either Maven or gradle. The following page was the closest to the search for "pom java JIRA api" etc. Even this is 2.0, which is quite old. https://community.atlassian.com/t5/Answers-Developer-Questions/JIRA-Rest-Java-Client-libraries/qaq-p/524054

Apparently, I found that the following libraries are keyword-like.

I also found that there is an API called JiraRestClientFactory.

Where did the tutorial JerseyJiraRestClientFactory go?

Now that I know the dependent libraries, I wrote pom with that as the key. Looking at "jira-rest-java-client-core maven", I found that version 4.0 is the newest. https://mvnrepository.com/artifact/com.atlassian.jira/jira-rest-java-client-core

What kind of API structure is it?

Now that the dependent libraries have been resolved, how do you use the API? I checked. Look for "JiraRestClientFactory example" as the key. http://massapi.com/class/ji/JiraRestClientFactory.html Was a hit.

Looking at the code, JiraRestClientFactory (interface) is the entry point, and it used to be the implementation class name Jersey…, but AsynchronousJiraRestClientFactory has a new name.

It has a structure to get JiraRestClient from Factory and search, update, etc.

━ JiraRestClientFactory (entry point) ┗ AsynchronousJiraRestClientFactory (implementation class) ┗ JiraRestClient (Client from the factory) ┣ IssueClient (sub-API group that can be obtained from RestClient)      ┣ SearchClient      ┗ ProjectClient

You can see it by looking at the JavaDoc of JiraRestClient.

After that, I found that it is the same as the tutorial if I replace it with Jersey → Asynchronous.

How do you authenticate?

https://developer.atlassian.com/jiradev/jira-apis/jira-rest-apis/jira-rest-api-tutorials Looking at this REST tutorial, I found that there are Basic, OAuth, etc. Looking at the sample code, it seems that Basic authentication can be done with the following code.

factory.createWithBasicHttpAuthentication(jiraServerUri, yourUsername, yourPassword);

How do you search?

I searched for "Search Client JIRA example". Anyway, it seems good to add an example. The next page was a hit, which also used the JerseyJiraRestClient for a long time, but it is helpful. http://stackoverflow.com/questions/29206524/how-to-get-all-issues-of-project-via-jira-rest-java-client

A simple sample just to search

From the above example, we can see that we can search with the following code. What is a Promise? I thought, but when I claim (), the iterator is returned. All you have to do is loop as in the example.

   Promise<SearchResult> searchJqlPromise = client.getSearchClient().searchJql("project = MYPURRJECT AND status in (Closed, Completed, Resolved) ORDER BY assignee, resolutiondate");

    for (Issue issue : searchJqlPromise.claim().getIssues()) {

Conclusion for making a sample to search for issues

1. In pom.xml, write the following.



    <!-- https://mvnrepository.com/artifact/com.atlassian.fugue/fugue -->

    <!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 -->

2. Get JiraRestClient with Basic authentication.

    JiraRestClientFactory factory = new AsynchronousJiraRestClientFactory();
    URI uri = new URI("https://your-project-name.atlassian.net");
    jiraRestClient = factory.createWithBasicHttpAuthentication(uri, userName, password);

3. Take an Issue using the Search Client.

The API was a little strange, but I got it with the following code.

    SearchRestClient searchRestClient = jiraRestClient.getSearchClient();
    final Set<String> fields = new HashSet<String>();
    String jql = "status!=done"; // Only not done issues.
    SearchResult result = searchRestClient.searchJql(jql, max, offset, fields).claim();
    Iterable<Issue> issues = result.getIssues();
    List<Issue> list = new ArrayList<Issue>();
    for (final Issue issue : issues) {

4. You can get the necessary information from the Issue API.


that's all.

Click here for the code.

Recommended Posts

Export issues using JIRA's Java API
I tried using Java8 Stream API
Data processing using stream API from Java 8
Try using the Stream API in Java
Try using JSON format API in Java
Java Stream API
Interact with LINE Message API using Lambda (Java)
ChatWork4j for using the ChatWork API in Java
[Java] API creation using Jerjey (Jax-rs) in eclipse
Try using GCP's Cloud Vision API in Java
Try using the COTOHA API parsing in Java
[Java] How to operate List using Stream API
Sorting using java comparator
I tried using Google Cloud Vision API in Java
[Java] Stream API / map
Docker-Client Java API Troubleshooting
Scraping practice using Java ②
Java8 Stream API practice
Zabbix API in Java
Scraping practice using Java ①
Elasticsearch Operation via REST API using Apache HttpClient in Java
Translate using Microsoft Translator Text API in Java (Japanese → English)
Tips for using Salesforce SOAP and Bulk API in Java
How to play MIDI files using the Java Sound API
Try using RocksDB in Java
Try scraping using java [Notes]
Java Stream API cheat sheet
Java Stream API in 5 minutes
[Java] Stream API --Stream termination processing
[Java] Stream API --Stream intermediate processing
Using Mapper with Java (Spring)
I tried using Java REPL
[Java] Introduction to Stream API
Using Docker from Java Gradle
Java Basic Learning Content 8 (Java API)
Make a rhombus using Java
[Java] Stream API intermediate operation
Recent Java API specification generation
Bubble sort using ArrayList (JAVA)
Sample of using Salesforce's Bulk API from Java client with PK-chunking