Skip to content


Subversion checkout URL

You can clone with
Download ZIP


Unit System option #8

merged 4 commits into from

2 participants


Fixes Issue #7 by adding optional unit_system parameter in client constructor. If not specified, fitbit responses will default to the metric system (as per their API design). Also changed the test to grab the profile of the current authorized user, because I found this to be a better test of the unit system switch. The old test used a fixed date for grabbing activity data, which wasn't always guaranteed to have any data. The profile should at least show some data. Also markdown referenced directory test which does not exist. Updated to say example.

@@ -20,7 +20,7 @@ module.exports = function (api_key, api_secret, callbackURI) {
api_key, api_secret, '1.0', callbackURI,
'HMAC-SHA1', null,
- {'Accept': '*/*', 'Connection': 'close', 'User-Agent': 'fitbit-js ' + client.version});
+ {'Accept': '*/*', 'Connection': 'close', 'User-Agent': 'fitbit-js ' + client.version, 'Accept-Language': unit_system});
@smurthas Owner
smurthas added a note

So that we don't end up sending an Accept-Language: undefined header to Fitbit, could you update this to only include it if is not null and not undefined?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Thanks! I put a small request comment on there. Other than that, it looks good.


I reworked the headers to only include Accept-Language if it isn't undefined or null

@smurthas smurthas merged commit e3993a1 into smurthas:master

LGTM, thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Dec 28, 2013
  1. Added unit system option to client constructor

    Chris Quartier authored
  2. fixed error in README

    Chris Quartier authored
  3. changed test to grab current auth'd user's profile

    Chris Quartier authored
Commits on Jan 9, 2014
This page is out of date. Refresh to see the latest.
Showing with 10 additions and 9 deletions.
  1. +2 −2
  2. +3 −3 example/test.js
  3. +5 −4 lib/fitbit_client.js
@@ -24,8 +24,8 @@ callback URL of `http://localhost:8553`.
npm install
-cd test
-node test.js [Consumer Key] [Consumer Secret]
+cd example
+node test.js [Consumer Key] [Consumer Secret] [Unit System (en_US or en_GB)](optional. Defaults to metric units)
open [http://localhost:8553](http://localhost:8553)
6 example/test.js
@@ -4,10 +4,10 @@ var app = express();
-var PORT = process.argv[4] || 8553;
+var PORT = process.argv[5] || 8553;
var fitbitClient = require('../')(process.argv[2], process.argv[3],
- 'http://localhost:' + PORT);
+ 'http://localhost:' + PORT, process.argv[4]);
var token;
app.get('/', function (req, res) {
@@ -21,7 +21,7 @@ app.get('/', function (req, res) {
app.get('/getStuff', function (req, res) {
- fitbitClient.apiCall('GET', '/user/-/activities/date/2011-05-25.json',
+ fitbitClient.apiCall('GET', '/user/-/profile.json',
{token: {oauth_token_secret: token.oauth_token_secret,
oauth_token: token.oauth_token}},
function(err, resp, json) {
9 lib/fitbit_client.js
@@ -12,16 +12,17 @@ var Serializer = require('serializer');
var baseURI = '';
-module.exports = function (api_key, api_secret, callbackURI) {
+module.exports = function (api_key, api_secret, callbackURI, unit_system) {
var client = {version: '0.1.0'};
var serializer = Serializer.createSecureSerializer(api_key, api_secret);
+ var headers = {'Accept': '*/*', 'Connection': 'close', 'User-Agent': 'fitbit-js ' + client.version};
+ if (typeof unit_system !== 'undefined' && unit_system !== null) headers['Accept-Language'] = unit_system;
var oAuth = new OAuth('',
api_key, api_secret, '1.0', callbackURI,
- 'HMAC-SHA1', null,
- {'Accept': '*/*', 'Connection': 'close', 'User-Agent': 'fitbit-js ' + client.version});
+ 'HMAC-SHA1', null, headers);
function requestCallback(callback) {
return function (err, data, response) {
Something went wrong with that request. Please try again.