簡體   English   中英

如何獲得 trello 列表的第一張卡片

[英]How to get the top card of a trello list

我想獲得某個 trello 列表的頂部卡片,然后讓它在我的 discord 頻道中發布卡片名稱,但是,我不確定如何獲得第一張卡片。

我建議你看看Trello Rest API 文檔

更精確的頁面滿足您的需求:

Trello 在這些頁面上提供了 Node.js 示例。

經過一番研究,這就是我設法獲得我在某個板上找到的列表中的第一張卡片的方法:

// Getting all lists from a certain board.
fetch(`https://api.trello.com/1/boards/{id}/lists?key={apiKey}&token={token}`, {
    method: 'GET',
}).then(response => {

    let lists = JSON.parse(response.body);
    // Searching for a list with a certain name and store it's id.
    let certainListId = lists.find(list => list.name === "listName").id;

    // Use the stored id in certainListId to get all cards of the list.
    fetch(`https://api.trello.com/1/lists/${certainListId}/cards`, {
        method: 'GET'
    }).then(response => {

        let certainListCards = JSON.parse(response.body);
        // Cards in the array is in top to bottom order. So top one is the very first.
        let firstCard = certainListCards[0];

        // Send with the bot the name of the first (top) card thanks to firstCard.name property.

    }).catch(err => console.error(err));

}).catch(err => console.error(err));

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM