[JAVA] Try to issue or get a card from Jave to Trello using API

Everyone's favorite task management tool Trello has an easy-to-use user interface and is easy to use.

I investigated whether the Trello API can be easily used to link the Trello with the service I am making, so I summarized it.

1. Preparation

To issue the API, you need to get a key and token instead of an ID and password. Get these first.

Log in to Trello.

https://trello.com/app-key

To access. Then, the key will be displayed, so make a note of it.

01.png

After that, click "Token" and the following screen will be displayed. Click "Allow".

02.png

The token will be displayed as shown below, so make a note of it.

03.png

Using this key and token, we will issue an API and issue a card to Trello.

2. Use Java wrapper library

There is a library called trello-java-wrapper on Github, so use that.

Although it is described in Gradle on the Github page, it is also in Maven, so use this.

<!-- https://mvnrepository.com/artifact/com.taskadapter/trello-java-wrapper -->
<dependency>
    <groupId>com.taskadapter</groupId>
    <artifactId>trello-java-wrapper</artifactId>
    <version>0.13</version>
</dependency>

First, create an instance of TrelloImpl. This example uses an http client based on the Apache Http library.

Trello trelloApi = new TrelloImpl(trelloKey, trelloAccessToken, new ApacheHttpClient());

By the way, if the following error occurs,

Exception in thread "main" java.lang.NoClassDefFoundError: com/fasterxml/jackson/core/exc/InputCoercionException

I think that adding "com.fasterxml.jackson.core" in Maven will fix it.

<!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
<dependency>
    <groupId>com.fasterxml.jackson.core</groupId>
    <artifactId>jackson-core</artifactId>
    <version>2.10.2</version>
</dependency>

3. Get a list of boards

First, get a list of boards like this. If you specify the member ID as "me", you can get all your own boards.

List <Board> boards = trelloApi.getMemberBoards("me", new Argument("fields", "name"));

If the following is specified for the parameter, the board name cannot be obtained, so it must be specified.

new Argument("fields", "name")

4. Get a list of lists and cards

Here's how to get the list on the board.

List <TList> lists = trelloApi.getBoardLists(boardId);

Here's how to get the cards in the list.

List <Card> cards = trelloApi.getListCards(listId);

By the way, if you code like this, you can get all the cards.

List <Board> boards = trelloApi.getMemberBoards("me", new Argument("fields", "name"));
for (Board board : boards) {
    board.getName();
    board.getId();
    System.out.println(board.getId() + ":" + board.getName());
    List <TList> lists = trelloApi.getBoardLists(board.getId());
    for (TList list : lists) {
        System.out.println(list.getId() + ":" + list.getName());
        List <Card> cards = trelloApi.getListCards(list.getId());
        for (Card card : cards) {
            System.out.println(card.getId() + ":" + card.getName());
        }
    }
}

5. Issue a card

When issuing a card, write it like this.

Card card = new Card();
card.setName("AIUEO");
card = trelloApi.createCard(listId, card); //Registration
card.addComment("Write a comment");
card = card.update(); //update
card.delete(); //Delete

When registering a new card, create a card with createCard, specify update when updating, and delete when deleting.

6. At the end

trello-java-wrapper supports a single API call, so you can easily call Trello's API from Java. I can. If you're using Trello, why not give it a try?

Below, reference site https://became-free.com/how-to-use-trello-api/ http://blog.serverworks.co.jp/tech/2016/05/16/trello-api/

Recommended Posts

Try to issue or get a card from Jave to Trello using API
Try using the Emotion API from Android
Try to get data from database using MyBatis in Micronaut + Kotlin project
How to get a heapdump from a Docker container
How to get an arbitrary digit from a number of 2 or more digits! !!
Try to make a music player using Basic Player
Try to get redmine API key with ruby
Try to make a timeline report of method execution time using JFR API
Try to implement using Rakuten product search API (easy)
How to convert A to a and a to A using AND and OR in Java
Try to build a Java development environment using Docker
How to get the latest live stream ID for a channel without using the YouTube Data API
I tried to create an API to get data from a spreadsheet in Ruby (with service account)
Try Spring Boot from 0 to 100.
Try using Cocoa from Ruby
I get a Ruby version error when I try to start Rails.
Easy way to create a mapping class when using the API
Try passing values from Java Servlet to iPhone app using JSON
Try to make a CS 3D tile from the Geographical Survey tile