Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Trello API: How to POST a Card from Google Apps Script (GAS)

Google Apps Script has a UrlFetchApp method capable of creating a card in Trello.

How can it be used to create/modify cards in trello?

like image 881
A. Perez Cera Avatar asked Aug 13 '13 16:08

A. Perez Cera


People also ask

How do I import a Google sheet into trello?

You can transfer the data from Google Sheets to your Trello card with this Google Sheets and Trello integration template. Just connect your accounts in Automate.io, activate the Bot, and you are done. Every time you fill a new row in Google Sheets, a Trello card will be created with the details customized by you.

How do I share a Google Apps project script?

To share a container-bound project, you simply share the parent container file. For example, if you have a script bound to a Google Sheet, you can make someone an editor of the script by making them an editor of the Google Sheet.


1 Answers

Using the sendHttpPost example from the docs for UrlFetchApp and the docs for the Trello API, I came up with this:

 // This sample sends POST payload data in the style of an HTML form, including
 // a file.

 function createTrelloCard() {

   //POST [/1/cards], Required permissions: write
   var payload = {"name":"apiUploadedCard", //(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": "", //(required) Valid Values: A date, or null
                  "idList":"52017776e823fa1d51000819", //(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=[YourAppKey]&token=[UserToken]' //optional... -&cards=open&lists=open'-
   var options = {"method" : "post",
                  "payload" : payload};

   UrlFetchApp.fetch(url, options);
 }

Disclaimer: I haven't tested this. I've never written a Google App script or used the Trello API.

like image 98
Justin York Avatar answered Nov 15 '22 10:11

Justin York