IBM’s Wearable Fitness API – an update

A few months ago I blogged about my developerWorks article on using IBM’s Bluemix with the wearable API service to do interesting things with Fitbit data and location services.

As with life, things are always changing, and at this time the Wearable Fitness API is no longer listed as an available option in the Bluemix service catalog.  Since then I’ve received several queries from those trying to follow my code examples from the article who are unsure of how to proceed.

First, the good news–the IoT Cloud Labs wearable API that backed the aforementioned Bluemix service is still alive and kicking, and more importantly, available to be used with registered devices as the article describes.  You can still follow the steps from the article to register a device, as well as register to use the API and receive an API key/credentials.

Once you have performed those steps as described in the article, configuring your Bluemix application to use the API will be very similar to how I configured the MapQuest API access in the article.  Given MapQuest is not available as a Bluemix service, once you have gotten your API credentials, you will create user-defined variables in Bluemix which are then readable from your code instead of accessing the service credentials via the VCAP_SERVICES environment.

Let’s look at these steps in detail:

1. Add the API access URL and API key as Bluemix user-defined variables

Go to your Bluemix application in your dashboard and select “Environment Variables” from the left sidebar menu.  You can then add the host and appId API key from the developer portal as shown below:

Bluemix wearables API env variables


2. Change the code to use the newly created environment variables above instead of reading VCAP_SERVICES to access the Wearable API

The file that requires this change if you are following along in my example application is routes/iot.js.   See the following code snippet for the couple of line changes from using iotprops (which was created from parsing VCAP_SERVICES) to directly reading our new environment variables:

function queryFitbitData(username, password, datestr, callbackFn)
    var restcall = require('../restcall');
    var host = process.env.wearablesHost;
    var authStr = username+":"+password;
    //switch to IOT 1.2 API endpoint due to problems with 1.0
    var endpoint = "/iotlabs1.2/doc?id="+username+":fb_activity_"+datestr

Once you have made these changes, you should be able to continue using the Wearable Fitness API from a Bluemix application until such a time as the service is reinstated in the catalog!

You may also like...

Leave a Reply

Your email address will not be published. Required fields are marked *