Trello – How to create card under a list in Trello

trello

I've failed creating list/card using HTTP post. It seems that I did not understand:

  1. How to build the HTTP request
  2. From where to get the list ID/card ID to fill in the HTTP request

Can you give some examples how to create list/card and from where do I get the relevant ID?

Best Answer

As an example of card creation, I describe a bookmarklet that I use to create Trello cards from Stack Exchange questions. (More serious applications, e.g., interfacing accounts of other users, would be a topic at Stack Overflow rather than here.)

Here is what you will need:

  1. Make sure you are logged in to Trello.
  2. Get app key by following instructions in Trello docs: it's as simple as following a link from there.
  3. Get a token for read/write access by following the URL below, and approving the request.

https://trello.com/1/authorize?key= put app key here &name=Your+App+Name&expiration=never&response_type=token&scope=read,write
  1. Visit the Trello board you want to use, and record the characters in the URL after https://trello.com/b/ (this is called "board id" below, although technically not the same thing).
  2. Get ids of the lists in this board by directing your browser to

https://api.trello.com/1/boards/ put board id here /lists?key= put app key here &token= put token here

(for reading the response, it helps if you have a browser extension for formatting JSON).

After collecting the above data, put it in the following script and use any bookmarklet generator to wrap it up.

key = 'put app key here';
token = 'put write-access token here';
lists = {stackoverflow: 'put list id here', webapps: 'put list id here'};
site = location.hostname.split('.')[0];
id = lists[site];
if (id) {
  opts = {name: $('#question-header a').text(), desc: location.href, idList: id, urlSource: null, due: null};
  $.post('https://trello.com/1/cards/?key='+key+'&token='+token, opts, function() {alert('Card added')});
} 

The script creates a card in your list for the SE site (assuming it exists), with the name being the title of the question, and the description being its URL (which becomes clickable in the Trello web interface). A confirmation message is shown.

Note: the bookmarklet uses jQuery. On Stack Exchange sites (and many others) jQuery is already loaded. If you are not sure if jQuery is available, include it with the bookmarklet (MrColes bookmarklet creator does this for you).