Skip to content

Instantly share code, notes, and snippets.

@jonodrew
Last active August 20, 2017 18:13
Show Gist options
  • Save jonodrew/7ffbfc977ad08e47c4cf2aff02df4a0b to your computer and use it in GitHub Desktop.
Save jonodrew/7ffbfc977ad08e47c4cf2aff02df4a0b to your computer and use it in GitHub Desktop.
function createTrelloCard(name, description, due) {
//POST [/1/cards], Required permissions: write
var payload = {name:name, //(required) Valid Values: a string with a length from 1 to 16384
desc:description, //(optional)Valid Values: a string with a length from 0 to 16384
pos:"top", //(optional) Default: bottom Valid Values: A position. top, bottom, or a positive number.
due: due, //(required) Valid Values: A date, or null
idList:"59834e0931c662f7628079bd", //(required)Valid Values: id of the list that the card should be added to
//"labels": ,//(optional)
//"idMembers": ,//(optional)Valid Values: A comma-separated list of objectIds, 24-character hex strings
//"idCardSource": ,//(optional)Valid Values: The id of the card to copy into a new card.
//"keepFromSource": ,//(optional)Default: all Valid Values: Properties of the card to copy over from the source.
};
// Because payload is a JavaScript object, it will be interpreted as
// an HTML form. (We do not need to specify contentType; it will
// automatically default to either 'application/x-www-form-urlencoded'
// or 'multipart/form-data')
var url = 'https://api.trello.com/1/cards?key=[public key]&token=[token]' //optional... -&cards=open&lists=open'-
var options = {"method" : "post",
"payload" : payload};
UrlFetchApp.fetch(url, options);
}
function myFunction() {
var ss=SpreadsheetApp.getActiveSpreadsheet();
var s=ss.getSheetByName('Responses')
var lr=s.getLastRow()
var values = s.getSheetValues(2, 5, lr-1,1); // Column is my "onTrello" variable. Don't want the top row, as that's labels
for (var i = 0; i < values.length; i++) {
var onTrello = values[i] // if onTrello is blank, I need to add it to my board
if (onTrello == "") {
var row = i + 2 // starting at row 2
var variables = s.getSheetValues(row, 2, 1, 3) // I need the variables from the 2nd, 2rd, and 4th columns - name, desc, due
var name = variables[0][0] // have to use [0] to get the 0th element from the array returned by line 36
var description = variables[0][1]
var due = variables[0][2]
var cell = 'E' + row // select the appropriate cell in column E, which is my onTrello column
createTrelloCard(name, description, due) // calls function above
ss.getRange(cell).setValue("Yes"); // set the cell's content to 'Yes' (so when I call it again in 5 mins, it'll skip this one)
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment