简体   繁体   中英

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.

I suggest you to take a look at Trello Rest API documentation

More precise pages for your need:

Trello gives Node.js example on these pages.

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));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM