Hello,
Inside Trello I have one list named Buffer, this is the first list on the board. The Buffer list consists of around 15 cards. Every Sunday 5 cards from the top of the Buffer list are moved to the next list named Translate. This cannot be done via Trello’s built in automation tool. So I asked ChatGPT for a solution to automate this.
ChatGPT suggested to use Code by Zapier. After a few attempts to solve the errors, there were no errors anymore. But no cards were moved when starting the script.
This is the script:
const Trello = require("node-fetch");
const apiKey = "apikey";
const apiToken = "apitoken";
const boardId = "boardid"; // Replace "boardId" with the actual ID of your Trello board
// Fetch the first list on the board
Trello(`https://api.trello.com/1/boards/${boardId}/lists?key=${apiKey}&token=${apiToken}`)
.then(res => res.json())
.then(lists => {
const firstList = listst0].id;
console.log(`First list ID: ${firstList}`);
// Fetch the cards in the first list
return Trello(`https://api.trello.com/1/lists/${firstList}/cards?key=${apiKey}&token=${apiToken}`);
})
.then(res => res.json())
.then(cards => {
console.log(`Moving ${cards.length} cards to the next list...`);
// Move the first 5 cards to the next list
const cardsToMove = cards.slice(0, 5);
const nextList = cardsd0].idList;
const movePromises = cardsToMove.map(card => {
return Trello(`https://api.trello.com/1/cards/${card.id}?idList=${nextList}&key=${apiKey}&token=${apiToken}`, {
method: "PUT"
});
});
// Wait for all cards to be moved before logging a message
return Promise.all(movePromises);
})
.then(() => {
console.log("Cards moved successfully!");
})
.catch(err => console.error(err));
// Your Code by Zapier code goes here
// Define the output object
const output = {
id: 1234,
message: "Card moved successfully!"
};
// Return the output object
callback(null, output);
The automation will be something like this:
- Inside Trello Butler automations will start every Sunday. It will post to url with payload "board id" and "numberofcardstomove". Because it will run on multiple boards. And the number of cards to move can be different.
- Inside Zapier the webhook will be the trigger.
- After this Code by Zapier starts, and this code will move x cards from the first list to the second list on the board.
Some questions:
- Does someone know if this is even possible to do with Code by Zapier?
- Where to store the api key and api token?
- Why is the script not working? Code by Zapier does not give any errors, but it's not working.