Automation: YNAB API

Over the last few months, I’ve enjoyed digging into automation technologies and finding new ways to shortcut common tasks, or blaze the trail to solve an unsolved problem I wish I could figure out. One way to do this is with a published application programming interface (API), which is essentially a specific way for programmers and computers to interact with a system or piece of software.

This week, I received a newsletter from the folks at YNAB (You Need A Budget), and since we’re very happy users of their software platform, I was pleased to see they’ve published a public API for their system. Immediately, I started to think about the possibilities for accessing our budget and financial details, but didn’t immediately have a project to try out. This weekend, however, I happened upon a question that I realized the YNAB API could help me solve.

Bean Counting, Automated

As part of my coffee-roasting hobby, I bring beans into work to share with my coworkers, and I’ve started receiving donations over the past year to help cover the cost of purchasing green coffee, etc. Since I’ve been tracking those donations in a specific budget category, I realized that I could use the API to figure out how much I’ve received in donations over a specific period of time. Normally, this would require that I fire up Excel or Numbers and total up the individual transactions in order to come up with a total. But the API now allows me to query my data live, and for any time period I want to.

Workflow To The Rescue, Again

The next question, of course, became: which tool to use? APIs can be used by almost all modern programming languages, many pre-built applications, and even a humble web browser. Since I’ve recently been gravitating towards using iOS more for the common, everyday things, I thought it would be worth giving Workflow a try. I already built a workflow that leveraged the ESV Bible version’s API a few weeks back. This seemed like the next logical step.

Turns out that the YNAB API requires a bit more “legwork” in order to drill down to the appropriate budget and category that you need, but after some poking around on my laptop, I got a URL query set up that could load all transactions for a specific category, on or after a specific date. With this in hand, I set up a workflow that asks for a start date and end date, and then runs out to YNAB in order to return a sum total of all income to my “Coffee Roasting” category. Of course, since the API returns all values after a date, I had to do my own checking to make sure the transaction date was between the date range provided in the workflow. It took some poking around, but I got it working!

Advanced Learning in Workflow

Along the way, I learned a few new tricks about the Workflow app that I didn’t know before, primarily the use of “magic” loop variables like “Repeat Item” and using multiple IF logic statements to process data. I also figured out how to work with numbers and do some basic math using workflow actions. Here’s a partial screenshot of the workflow:
Part of the processing of the actual transaction amounts…

The end result is that I can now see a total of all income to my Coffee Roasting category for a month, the last week, or every year-to-date. Very handy!

Future Integrations and Automation

Although this is a simple use of the YNAB API, I’m still very pleased that I can use an app like Workflow to grab this kind of data and massage it into something useful. Since this is pretty specific to my use cases, I’m not sharing this one with the world. However, I’m already thinking about an Alfred workflow that I could put together for this… but that will have to wait for another time, or until some other smart automator does it before I do.