Trello API Basics

Trello is a pretty awesome tool for basic scrum needs and or task management. What is even better is its RESTful API; however the documentation could have been a thousand times better. So I am going to go through some “Getting Started with Trello API Basics” to hopefully help your team get up to speed fast and begin leveraging the API in your automation workflows.

Getting Started

First we need to get all of the application keys, tokens and your board ID. This is pretty straight forward for the most part.

Get Application Key

Getting your API Key is simple, just visit: https://trello.com/1/appKey/generate

Get Authenication Token

Now that we have the API Key we can start using the API to gather the rest of the tokens we need to start working with the board. In most cases a forever read-only token seems to be the best solution for data gathering. You can get that here:
https://trello.com/1/authorize?key=substitutewithyourapplicationkey&name=My+Application&expiration=never&response_type=token. Note: You need to update substitutewithyourapplicationkey with the API Key we got earlier.

If you need read/write access or any other special access please see: https://trello.com/docs/gettingstarted/index.html#getting-a-token-from-a-user

Get Board ID

Visit the following link for a json object of all of your boards where you can get the board id: https://trello.com/1/members/me/boards?fields=name

Getting Basic Board Details

Now that we have all of the basic details needed to work with the API we can start pulling data. So first lets build are basic request:

#!/usr/bin/python
'''
Basic GET request to trello API to pull basic board details
'''
import json
import requests

app_key  = 'app_key_goes_here'
token    = 'your_auth_token_goes_here'
board_id = 'board_id_goes_here'
url      = 'https://api.trello.com/1/board/' + board_id + '?key=' + app_key + '&token=' + token
r        = requests.get(url)
print json.dumps(r.text)

This will return a json object with the base data of your trello board. Not the most useful functionality or data. Moving forward we will look at some of the more useful API endpoints that we can work with.

Pulling all the active cards on a board

This API endpoint allows you to return a JSON object of all the cards currently active on the board.

url = 'https://api.trello.com/1/board/' + board_id + '/cards/?key=' + app_key + '&token=' + token

Pulling comments on a given card id

card_id = '' # Usually populated via the previous call and then the following endpoint used in a loop
url     = 'https://api.trello.com/1/board/' + board_id + '/cards/' + card_id + '/actions?key=' + app_key + '&token=' + token

Get the column name that a card is currently in

list_id = '' # Pulled from idList field in /cards/ API call
url     = 'https://api.trello.com/1/lists/' + list_id + '/?key=' + app_key + '&token=' + token

Further reading

The trello API is vast and I hope that I was able to provide you with a quick introduction, see the full API documentation here:
https://trello.com/docs/

Write a Comment

Your email address will not be published. Required fields are marked *

This site uses Akismet to reduce spam. Learn how your comment data is processed.