Skip to main content
under engineered

Automate Trello overnight!

I was recently bitten by the todo-list-obsession-bug to make myself super organized.

I now have so many TODOs and no work done :P

Jokes aside, there are a lot of todo apps, but Trello is my favourite. It has everything you need - except (enough free) automation!

what happens when you want to create a todo in trello? #

You create a todo. But it isn't enough. You need to

And when you want to finish a todo. You need to

If you just drag it to done list and don't check the due date, it continues to show as pending.

So you see, you need some automation. If you want you can choose the business class and spend money to use Butler, Trello's in-house automation. But a quick look at the quotas doesn't look as generous and you'll still fall short.

hacking to the rescue #

I used Trello's Webhooks and its rest api to automate the tasks as per my whims and fantasies. I used Google Cloud Functions as they've a very generous free quota.

Webhooks are events that trello publishes to a URL (api hosted by you) anytime something happens on your board. Webhooks are nothing but published events that you've subscribed to.

So anytime you add a new todo, a webhook is triggered, and you can decide what to do now.

You mark a todo finished you get a call again with the event payload. Payload tells you what changed in the system.

step 1 #

step 2 #

exports.automate = (req, res) => {
  if (req.get("content-type") === "application/json") {
    // we'll define this later
    handle(req.body);
  }

  res.status(200).send("thanks!");
};
google cloud page for permissions

step 3 #

step 4 #

I now want to achieve a few things for my own workflow. I've started with two boards

All my personal tasks like bills, taxes, bank, credit cards stuff go into them. For these tasks

To do this, I need to listen on the events and call the appropriate API by reading the docs.

example: setting the due date to weekend #

Remember the handle function in the first code snippet?

function handle({ model, action }) {
  const board = model.name;

  const eventType = action.type;
  const card = action.data.card;
  const cardId = card.id;
  switch (eventType) {
    case "createCard": {
      if (!card.due) {
        updateCard(cardId, {
          due: getDueDate(board), // some ugly logic to get next Saturday
        });
      }
    }
  }
}

In the above code snippet, updateCard does a plain ol' fetch call.

fetch(`https://api.trello.com/1/cards/${cardId}?due=<date>&key=k&token=t`, {
  method: "PUT",
  headers: {
    Accept: "application/json",
  },
});

Please see the details of exact API call from the docs, most of the params are passed as query params.

closing #

This was a fun evening tinkering the API and making something custom-made. I hope it inspired you to go and build one for yourself too.

Thanks friends!

(my trello board after doing this - lol)

trello board

discuss on twitter, because why not?