Trello: Archive Card

Trello: Archive Card

Trello: カードをアーカイブ

This item archives cards 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_CardIds
C3: Card IDs (write one per line) *

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

Capture

See Also

Script (click to open)
  • An XML file that contains the code below is available to download
    • trello-card-archive.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 apiKey = authKey.getToken();
    const apiToken = authToken.getToken();

    const cardIdsArray = retrieveCardIds();

    //// == Calculating / 演算 ==
    const numOfLines = cardIdsArray.length;
    for (let i = 0; i < numOfLines; i++) {
        archiveCard(apiKey, apiToken, cardIdsArray[i]);
    }
}

/**
  * config からカード ID を読み出す
  * @return {String} cardIds
  * @return {Array<String>} linesArray  カード ID の配列
  */
function retrieveCardIds() {
    const cardIdsDef = configs.getObject('conf_CardIds');
    const cardIds = engine.findData(cardIdsDef);

    if (cardIds === null || cardIds === "") {
        throw new Error("Card IDs aren't set.");
    }

    let linesArray = cardIds.split("\n");
    linesArray = linesArray.filter(lines => lines !== ""); // 空文字列を削除
    if (linesArray.length === 0) {
        throw new Error("Card IDs aren't set.");
    }

    const numOfLines = linesArray.length;
    if (numOfLines > httpClient.getRequestingLimit()) {
        throw new Error("Number of Card IDs is over the limit.");
    }
    return linesArray;
}


/**
  * カードをアーカイブする
  * @param {String} auth.apiKey
  * @param {String} auth.apiToken
  * @param {String} cardId
  */
function archiveCard(apiKey, apiToken, cardId) {

    const url = `https://api.trello.com/1/cards/${encodeURIComponent(cardId)}`;
    const response = httpClient.begin()
        .queryParam("key", `${apiKey}`)
        .queryParam("token", `${apiToken}`)
        .queryParam("closed", "true")
        .put(url);
    const status = response.getStatusCode();
    const responseStr = response.getResponseAsString();
    if (status !== 200) {
        engine.log(responseStr);
        throw new Error(`Failed to archive. Card ID: ${cardId}, status: ${status}`);
    } else {
        engine.log(`Succeeded to archive. Card ID: ${cardId}`);
    }
}

    

Discover more from Questetra Support

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

Continue reading