const path = require('path'); require('dotenv').config({ path: path.join(__dirname, '../../../../.env') }); const API_KEY = process.env.TRELLO_API_KEY; const TOKEN = process.env.TRELLO_TOKEN; if (!API_KEY || !TOKEN) { console.error("Error: TRELLO_API_KEY or TRELLO_TOKEN is missing from the .env file."); process.exit(1); } const listId = process.argv[2]; const cardName = process.argv[3]; const cardDesc = process.argv[4] || ""; if (!listId || !cardName) { console.error(`Usage: node create_card.js "${card_name}" ["${card_description}"]`); process.exit(1); } async function createCard() { const url = `https://api.trello.com/1/cards?idList=${listId}&key=${API_KEY}&token=${TOKEN}`; try { const response = await fetch(url, { method: 'POST', headers: { 'Accept': 'application/json', 'Content-Type': 'application/json' }, body: JSON.stringify({ name: cardName, desc: cardDesc, pos: 'top' }) }); if (!response.ok) { const errText = await response.text(); throw new Error(`HTTP error! status: ${response.status}, message: ${errText}`); } const card = await response.json(); console.log(`Successfully created card!`); console.log(`Name: ${card.name}`); console.log(`ID: ${card.id}`); console.log(`URL: ${card.url}`); } catch (error) { console.error("Failed to create card:", error.message); } } createCard();