简体   繁体   English

如何获得 trello 列表的第一张卡片

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

I want to get the top card of a certain trello list and then have it post the cards name in my discord channel, however, I'm unsure how to get the very first card.我想获得某个 trello 列表的顶部卡片,然后让它在我的 discord 频道中发布卡片名称,但是,我不确定如何获得第一张卡片。

I suggest you to take a look at Trello Rest API documentation我建议你看看Trello Rest API 文档

More precise pages for your need:更精确的页面满足您的需求:

Trello gives Node.js example on these pages. Trello 在这些页面上提供了 Node.js 示例。

After some research, this is how I manage to get the first card of a list that I found on a certain board by it's name:经过一番研究,这就是我设法获得我在某个板上找到的列表中的第一张卡片的方法:

// 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