Sync Fitbit workouts to Toggl

Fitbit to Toggl

I'm a big fan of data, any kind of chart or visualisation about even trivial datasets get me pretty interested in the subject matter really quickly. No surprise then that r/dataisbeautiful has been one of my favourite time killers ever since I stumbled upon it.

Some of the most interesting data we have is about ourselves, or at least that's how I see it. I've been tracking my personal productive time on Toggl for about a year now and it has been really interesting seeing how my productivity and interest in certain topics ebbs and flows.

Throughout all this time I've been wearing my Fitbit 24/7, because I really like the data it gives me about my general fitness and efforts to keep myself somewhat in a shape that doesn't look like a circle.

Talking to my buddy Daniel this morning he told me he has a way to combine Toggl projects into "buckets" (as in groups) and he has been toying around with the idea to orientate his goals in a way which matches these buckets. I mentioned that I like having fitness as something that is in its own bucket, as for me it helps keep me energised. I also immediately realised I've got no tangible display of my efforts other than the Fitbit heart rate chart (as wonky as it is).

Wait a minute, a while ago I set up a Function as a Service (FaaS) on webtask.io that runs on a schedule to help get me out of bed in the morning (also credit to Daniel for the idea).

I have previously set up a Fitbit API cache server in Dotnet Core so I know I can get my workout data from their API, what if I set up a Webtask function to run every night and sync my daily workouts to a Toggl project?

It would be really easy.

Sync Daily workout data to Toggl

All you need to get this going is:

Some time.

A Fitbit API key from here: dev.fitbit.com

Your Toggl API key and project ID.

A webtask.io account.

My lovely code on GitHub toggl-to-workouts.js

Once you have all of the above go ahead and add the code to a new Webtask function on https://webtask.io/make, then we need to set up some environment details.

First, make sure you add the following Secrets and enter your corresponding API keys and project ID.

FITBIT_API_TOKEN TOGGL_API_TOKEN TOGGL_PROJECT_ID

Then we need to make sure to add the following NPM Modules.

You could probably use different versions if you really wanted to.

Give it a go by pressing the play button for the Runner, check your Toggl to confirm that it worked. Great stuff!

Now let's set it up to run on a schedule.

I like to have mine run at 11 pm each night, feel free to change to what best suits your needs. Remember it only syncs workouts from the day that it is run on.

Sync all workout data for the year

Now you might be telling me "Hey Jacob, that's really cool mate but how do I add all the workouts from the past year?". Well, I'm glad you asked such an oddly specific question, let me show you how.

First clone this Dotnet Core 2.1 app from the GitHub repo.

Open it up in Visual Studio and update the "Secret" variables at the top, the same details you used for them on Webtask will work here. With that done you can start it and watch it sync all the workout data you have for the current year.

If you found this useful come give us a star on Github and share your ideas.

Thanks for stopping by.