My Alfred Trello Workflow

This post could also be called “why is it so hard to find information on programmatically creating items in Trello”? or “why are the Trello python modules so awful”?

What I was looking to do was create an Alfred workflow that would allow me to create a new item in an existing Trello list.

When you type in “backlog” into Alfred without any options, it’ll just open the Trello website, but if you type “backlog and the title” into Alfred, it’ll create a card with that topic in your Backlog list.

To get the data into the list, I used a simple python script that looks like this:

#!/usr/bin/env python


import requests
import argparse

parser = argparse.ArgumentParser()
parser.add_argument('--name', required=True, help='name of the card')
parser.add_argument('--description', default='' , help='description of the card')
args = parser.parse_args()

api_key='MYGREATKEY'
token='MYGREATTOKEN"
idList='ID_OF_MY_LIST'

# https://developers.trello.com/reference#cards-2
url = "https://api.trello.com/1/cards"
querystring = { "idList":idList,
               "keepFromSource":"all",
               "key":api_key,"token":token,
               "name": args.name,
               "desc": args.description}

response = requests.request("POST", url, params=querystring)
# print(response.text)

The api_key and token can be found here. and the idList value can be found by doing a query of the board that your list is on.

# get the idList variable from this
response=requests.get("https://api.trello.com/1/boards/Kwd0PbRP/cards/?key={}&token={}".format(api_key, token))
print(response.text)

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s