Playing with Trello using jq
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:
- Get an API key from here. Say the generated string is
apiKey
. - 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 isapiToken
. - 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
andtoken
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):
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:
Now, by combining this with curl you can easily get the names of all open cards with the following command:
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.