I'm a big fan of Runkeeper and the Jawbone UP, so I was delighted when they announced that both companies were providing compatibility with each others' services. Unfortunately, the data sharing seems to only go from Runkeeper to Jawbone's network.
I regularly run with Runkeeper anyway, so that's not a problem, but I prefer using the UP to track my sleep (over the various sleep apps).
Given that the UP also integrates with IFTTT, and Runkeeper has a pretty sweet API, I figured there must be a way to get my sleep data out of UP and into Runkeeper.
After a few hours of Googling and hacking, I thought I'd cracked it:
I *think* I've figured out a way to log sleep from the UP to @Runkeeper using @IFTTT, @Dropbox, and a smidgen of Ruby on Rails.
— Vinny Coyne (@vinnycoyne) July 19,2013
Unfortunately, ifttt's Dropbox recipes don't support URL encoding, so I was back to square one. Luckily, I stumbled across the ifttt-webhook project, which allows certain triggered events to POST data to an external webserver. This was the exact solution I needed.
1. Getting your RunKeeper API details
Register a new app with Runkeeper (I requested all permissions, but you may not need to). Once registered, click on the Keys and URLs link. Make note of your Client ID and Client Secret.
2. Getting a RunKeeper API token
There are a number of ways to generate an API token for the Runkeeper API. The method I've listed below is a little convoluted, but I'd initially started writing the API bridge in Rails before I discovered the existing Wordpress method (more on that later).
Clone the runkeeper-bridge repo:
git clone [email protected]:appsandwich/runkeeper-bridge.git
cd runkeeper-bridge
gem install launchy rack
The next command will open a browser window and ask you to authenticate against your Runkeeper account. Once you've done this, switch back to your Terminal window and you should see your Access Token printed on-screen.
Note: If you're having trouble with the command below, try typing it out instead of copy-and-pasting, as Tumblr has a bad habit of changing the quotation marks.
CLIENT_ID="your Client ID" CLIENT_SECRET="your Client Secret" AUTHORIZATION_URL="https://runkeeper.com/apps/authorize" ACCESS_TOKEN_URL="https://runkeeper.com/apps/token" token_generator
Once you've retrieved your access token, you can delete the runkeeper-bridge folder, as you'll no longer need it.
3. Creating a Fake Wordpress Install
This cool hack allows you to simulate a Wordpress install, which will successfully auth with ifttt's Wordpress channel. I've written a plugin for this, which connects to the Runkeeper API when ifttt sends it a new post. You can host this project on any PHP server - I've used Heroku because it's free and deployment is super-simple.
Clone the repo at https://github.com/appsandwich/ifttt-webhook
git clone [email protected]:appsandwich/ifttt-webhook.git
cd ifttt-webhook
Look for the runkeeper.php file in the plugins folder and open it in any text editor. Around line 58, change the YOUR_ACCESS_TOKEN text to the token generated earlier in step 2.
git add . -A
git commit -m "Updated access token"
heroku create
git push heroku master
heroku open
This will open your webhook site in your browser. Take note of the URL, as you'll need this later.
Note: I've never written PHP before, so please feel free to submit patches for the Runkeeper plugin! :)
4. Create the IFTTT Recipe
Go to IFTTT.com and authenticate the UP channel.
Next, authenticate the Wordpress channel. Use the webhook site URL (the fake Wordpress site created in step 2) as your blog URL. Username and password can be anything (I just used "ifttt" for both).
Now, create a new recipe:
Trigger: UP channel, new sleep logged
Action: Wordpress channel, new post
In the Wordpress New Post action options, enter the following:
Title: Doesn't matter - default setting is fine.
Body:
{"timestamp":"{{FellAsleepAt}}","total_sleep":{{TotalTimeSleptInSeconds}},"deep":{{TimeInDeepSleepSeconds}},"light":{{TimeInLightSleepSeconds}},"awake":{{TimeAwakeSeconds}},"post_to_twitter":"false","post_to_facebook":"false"}
Categories: plugin:runkeeper
Tags: https://YOUR_FAKE_WORDPRESS_APP.herokuapp.com
Post status: Publish immediately
That's it! You should be ready to go. Next time you sync sleep from your UP to the UP app, IFTTT will pick up the data, post it to your Wordpress install on Heroku, which in turn will pass that data to the Runkeeper API.
Are you a Runner? Check out Pace.fm—a distraction-free way to keep track of your current pace, while running, walking, or cycling. Available now on the App Store.