I love Trello and use it on a daily basis. Although its web interface is good, it would be nice to access the boards from the command line. Fortunately, Trello has a pretty decent API and you don’t have to play with the JSON export functionality (which would require annoying cookie setup). I’ll quickly demonstrate how it works.

To access Trello, you’ll need:

  • your own Trello application with read-only access to your account (it’s easier than it sounds)
  • jq
  • of course, the good old curl :)

The steps to set it up are easy:

  1. Get an API key from here. Say the generated string is apiKey.
  2. To request a token for read-only access to your account (without an expiration) you just need to open this URL in your browser, substituting <apiKey>: https://trello.com/1/authorize?key=<apiKey>&name=CLI+Magic&expiration=never&response_type=token. The application name doesn’t matter much. Let’s say the token you got is apiToken.
  3. That’s all! Now you can use the various Trello API endpoints using the key and the token. It’s as easy as adding key and token query parameters.

For example, suppose you want to access all open cards on a board. First, you have get the board ID from the URL in the Trello web interface. Then you just have to GET https://api.trello.com/1/board/<boardId>/cards?key=<apiKey>&token=<apiToken>, substituing the three strings.

The result is a nice JSON that looks like this (and, of course, has a lot more properties):

    "closed": false,
    "name": "Foo"
    "closed": true,
    "name": "Bar"

To make the API output human-readable you can process it with jq. It’s a pretty powerful tool for JSON manipulation. You can see the tutorial for a quick glance of the simple expression language that jq uses.

The jq expression that filters all cards that are not closed and returns their names is:

jq '.[] | select(.closed == false) | .name'

Now, by combining this with curl you can easily get the names of all open cards with the following command:

curl -s https://api.trello.com/1/board/<boardId>/cards\?key=<api>curl -s https://api.trello.com/1/board/<boardId>/cards\?key=<api>curl -s https://api.trello.com/1/board/<boardId>/cards\?key=<api>curl -s https://api.trello.com/1/board/<boardId>/cards\?key=<api>\&token=<token> | jq '.[] | select(.closed == false) | .name'amp;token=<token> | jq '.[] | select(.closed == false) | .name'amp;token=<token> | jq '.[] | select(.closed == false) | .name'amp;token=<token> | jq '.[] | select(.closed == false) | .name'

Note that this URL will be valid forever - we set never for API key expiration.

More information about the Trello API can be found here. The jq manual is here.