Created
August 26, 2024 15:00
-
-
Save gmdias727/39934ee261cd53b51cfebe2da484af76 to your computer and use it in GitHub Desktop.
GET ALL CARDS FROM TRELLO BOARD
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import fetch from 'node-fetch'; | |
import fs from "fs"; | |
import { formatDate } from "date-fns" | |
// provide the following | |
const key = "" | |
const token = "" | |
const boardId = "" | |
fetch(`https://api.trello.com/1/boards/${boardId}/cards?key=${key}&token=${token}`, { | |
method: 'GET', | |
headers: { | |
'Accept': 'application/json' | |
} | |
}) | |
.then(response => { | |
if (!response.ok) return "bad request >.<" | |
return response.json(); | |
}) | |
.then(output => { | |
const formattedOutput = output.map(e => ({ | |
name: e.name, | |
dateLastActivity: formatDate(new Date(e.dateLastActivity), "dd/M/yyyy") | |
})); | |
formattedOutput.sort((a, b) => new Date(a.dateLastActivity) - new Date(b.dateLastActivity)); | |
const newReturn = formattedOutput.map(line => { | |
return `${line.dateLastActivity} ${line.name}`; | |
}); | |
var print_to_file = JSON.stringify(newReturn, null, "\t") | |
fs.writeFile('out.txt', print_to_file, (err) => { | |
if (err) throw err; | |
console.log("output saved to out.txt"); | |
}) | |
}) | |
.catch(err => console.error(err)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment