Trello: Get List ID

Trello: Get List ID

Trello: リスト ID 取得

This item gets a list ID on Trello.

Basic Configs
Step Name
Note
Auto Step icon
Configs for this Auto Step
conf_ApiKey
C1: Authorization Setting in which API Key is set *
conf_ApiToken
C2: Authorization Setting in which API Token is set *
conf_BoardId
C3: Board ID *
conf_ListName
C4: List Name *
conf_ListId
C5: Data item to save List ID *

Notes

  • To get your API Key and API Token,
    1. Open the Power-Ups administration page and create a new Power-Up
    2. Proceed to the “API Key” page from the left menu, and your API Key is shown on the page
    3. Click the link in “you can manually generate a Token” to the right of the API Key to get your API Token
  • To get your board ID,
    1. Open your Trello Board in your browser
    2. Add “.json” at the end of the URL in the address bar, and JSON of the board information will be shown
    3. The value of “id” is your board ID

Capture

See Also

Script (click to open)

  • An XML file that contains the code below is available to download

    • trello-listid-get.xml (C) Questetra, Inc. (MIT License)
    • If you are using Professional, you can modify the contents of this file and use it as your own add-on auto step



function main() {
    //// == 工程コンフィグ・ワークフローデータの参照 / Config & Data Retrieving ==
    const authKey = configs.getObject("conf_ApiKey");
    const authToken = configs.getObject("conf_ApiToken");
    const boardId = configs.get('conf_BoardId');//固定値指定のみ 必須
    const listName = configs.get('conf_ListName');//固定値指定のみ 必須
    const listIdDef = configs.getObject('conf_ListId');

    const apiKey = authKey.getToken();
    const apiToken = authToken.getToken();

    //// == Calculating / 演算 ==
    const listObj = getListInformation(apiKey, apiToken, boardId);
    const trelloListId = getListId(listObj, listName);

    engine.setData(listIdDef, trelloListId);
}


/**
  * ボード内のリスト情報を取得する
  * @param {String} auth.apiKey
  * @param {String} auth.apiToken
  * @param {String} boardId
  * @return {Object} list
  */
function getListInformation(apiKey, apiToken, boardId) {

    const url = `https://api.trello.com/1/boards/${boardId}/lists?key=${apiKey}&token=${apiToken}`;
    const response = httpClient.begin()
        .get(url);
    const status = response.getStatusCode();
    const responseStr = response.getResponseAsString();
    if (status !== 200) {
        engine.log(responseStr);
        throw `Failed to get list information. status: ${status}`;
    }
    return JSON.parse(responseStr);
}


/**
  * リスト情報からリスト名に対応するリスト ID を取得する
  * @param {Object} listObj  リスト情報の JSON オブジェクト
  * @param {String} listName リスト名
  * @return {String} listId  リスト ID
  */
function getListId(listObj, listName) {

    let listId;
    let index = listObj.findIndex((listElement) => listElement.name === listName);
    if (index !== -1) {
        listId = listObj[index].id
    } else {
        throw `List name: "${listName}" not found in the Board`;
    }

    return listId;
}
    

Scroll to Top

Discover more from Questetra Support

Subscribe now to keep reading and get access to the full archive.

Continue reading