1.3.0 • Published 6 years ago

hypertonic v1.3.0

Weekly downloads
3
License
MIT
Repository
github
Last release
6 years ago

Hypertonic

npm version

Fitbit API Wrapper :running: :tropical_drink:

hypertonic is a Fitbit web api wrapper that only requires your access token to get started.

BranchStatus
masterCircleCI Coverage Status Known Vulnerabilities Bundle size
developCircleCI Coverage Status

Example

const Hypertonic = require('hypertonic');

const token = '<YOUR_FITBIT_ACCESS_TOKEN>';
const hypertonic = Hypertonic(token);

// Activity Summary data
hypertonic.getSummary('today').then(data => console.log(data));

// Activity Time Series
hypertonic.getTimeSeries('calories', 'today', '7d').then(data => console.log(data));
hypertonic.getTimeSeries('steps', 'today', '1m').then(data => console.log(data));

API Reference

Hypertonic(token) ⇒ Function

ParamType
tokenany

Hypertonic~getProfile() ⇒ Promise

Kind: inner method of Hypertonic

Hypertonic~getLifetimeStats() ⇒ Promise

Get Lifetime Stats

The Get Lifetime Stats endpoint retrieves the user's activity statistics in the format requested using units in the unit system which corresponds to the Accept-Language header provided. Activity statistics includes Lifetime and Best achievement values from the My Achievements tile on the website dashboard. Response contains both statistics from the tracker device and total numbers including tracker data and manual activity log entries as seen on the Fitbit website dashboard.

Kind: inner method of Hypertonic

Hypertonic~getInvitations() ⇒ Promise

Get Friend Invitations

The Get Friend Invitations endpoint returns a list of invitations to become friends with a user in the format requested.

Kind: inner method of Hypertonic

Hypertonic~getBadges() ⇒ Promise

Get Badges

The Get Badges endpoint retrieves user's badges in the format requested. Response includes all badges for the user as seen on the Fitbit website badge locker (both activity and weight related). Fitbit returns weight and distance badges based on the user's unit profile preference as on the website.

Kind: inner method of Hypertonic

Hypertonic~getFrequentActivities() ⇒ Promise

Get Frequent Activities

The Get Frequent Activities endpoint retrieves a list of a user's frequent activities in the format requested using units in the unit system which corresponds to the Accept-Language header provided. A frequent activity record contains the distance and duration values recorded the last time the activity was logged. The record retrieved can be used to log the activity via the Log Activity endpoint with the same or adjusted values for distance and duration.

Kind: inner method of Hypertonic

Hypertonic~getRecentActivities() ⇒ Promise

Get Recent Activity Types

The Get Recent Activity Types endpoint retrieves a list of a user's recent activities types logged with some details of the last activity log of that type using units in the unit system which corresponds to the Accept-Language header provided. The record retrieved can be used to log the activity via the Log Activity endpoint with the same or adjusted values for distance and duration.

Kind: inner method of Hypertonic

Hypertonic~getFavoriteActivities() ⇒ Promise

Get Favorite Activities

The Get Favorite Activities endpoint returns a list of a user's favorite activities.

Kind: inner method of Hypertonic

Hypertonic~getFood(foodType) ⇒ Promise

Get Food

The Get Food endpoint returns the details of a specific food in the Fitbit food database or a private food the authorized user has entered in the format requested.

Kind: inner method of Hypertonic

ParamType
foodTypeany

Hypertonic~getFavoriteFoods() ⇒ Promise

Get Favorite Foods

This endpoint returns a list of a user's favorite foods in the format requested. A favorite food in the list provides a quick way to log the food via the Log Food endpoint.

Kind: inner method of Hypertonic

Hypertonic~getFrequentFoods() ⇒ Promise

Get Frequent Foods

This endpoint returns a list of a user's frequent foods in the format requested. A frequent food in the list provides a quick way to log the food via the Log Food endpoint.

Kind: inner method of Hypertonic

Hypertonic~getRecentFoods() ⇒ Promise

Get Recent Foods

The Get Recent Foods endpoint returns a list of a user's recent foods in the format requested. A recent food provides a quick way to log the food via the Log Food endpoint.

Kind: inner method of Hypertonic

Hypertonic~getMeals() ⇒ Promise

Get Meals

This endpoint returns a list of meals created by user in his or her food log in the format requested. Meals in the list provide a quick way to log several foods at a time via the calls to the Log Food endpoint.

Kind: inner method of Hypertonic

Hypertonic~getMeal(mealId) ⇒ Promise

Get Meal

The Get Meal endpoint retrieves a meal for a user given the meal id.

Kind: inner method of Hypertonic

ParamType
mealIdany

Hypertonic~getFoodUnits() ⇒ Promise

Get Food Units

The Get Food Units endpoint returns a list of all valid Fitbit food units in the format requested.

Kind: inner method of Hypertonic

Hypertonic~getFoodLocales() ⇒ Promise

Get Food Locales

The Get Food Locales endpoint returns the food locales that the user may choose to search, log, and create food in.

Kind: inner method of Hypertonic

Hypertonic~getFoodGoals() ⇒ Promise

Get Food Goals

The Get Food Goals endpoint returns a user's current daily calorie consumption goal and/or food Plan in the format requested.

Kind: inner method of Hypertonic

Hypertonic~getWaterGoals() ⇒ Promise

Get Water Goals

The Get Water Goals endpoint returns a user's current daily water consumption goal.

Kind: inner method of Hypertonic

Hypertonic~getFoodTimeSeries(from, to) ⇒ Promise

Get Food Time Series

The Get Food or Water Time Series endpoint returns time series data in the specified range for a given resource in the format requested using units in the unit systems that corresponds to the Accept-Language header provided.

Kind: inner method of Hypertonic

ParamType
fromany
toany

Hypertonic~getWaterTimeSeries(from, to) ⇒ Promise

Get Water Time Series

The Get Food or Water Time Series endpoint returns time series data in the specified range for a given resource in the format requested using units in the unit systems that corresponds to the Accept-Language header provided.

Kind: inner method of Hypertonic

ParamType
fromany
toany

Hypertonic~getDevices() ⇒ Promise

Get Devices

The Get Device endpoint returns a list of the Fitbit devices connected to a user's account.

Kind: inner method of Hypertonic

Hypertonic~getAlarms(trackerId) ⇒ Promise

Get Alarms

The Get Alarms endpoint returns a list of the set alarms connected to a user's account.

Kind: inner method of Hypertonic

ParamType
trackerIdany

Hypertonic~getActivityTypes() ⇒ Promise

Activity Types List

Get a tree of all valid Fitbit public activities from the activities catalog as well as private custom activities the user created in the format requested. If the activity has levels, also get a list of activity level details.

Kind: inner method of Hypertonic

Hypertonic~getActivityGoals(period) ⇒ Promise

Get Activity Goals

The Get Activity Goals retrieves a user's current daily or weekly activity goals using measurement units as defined in the unit system, which corresponds to the Accept-Language header provided.

Kind: inner method of Hypertonic

ParamType
periodany

Hypertonic~getActivityType(activityId) ⇒ Promise

Get Activity Type

Returns the details of a specific activity in the Fitbit activities database in the format requested. If activity has levels, also returns a list of activity level details.

Kind: inner method of Hypertonic

ParamType
activityIdany

Hypertonic~getBodyGoal(bodyMetric) ⇒ Promise

Get Body Goals

The Get Body Goals API retrieves a user's current body fat percentage or weight goal using units in the unit systems that corresponds to the Accept-Language header provided in the format requested.

Kind: inner method of Hypertonic

ParamType
bodyMetricany

Hypertonic~getFriends(friends) ⇒ Promise

Get Friends

The Get Friends endpoint returns data of a user's friends in the format requested using units in the unit system which corresponds to the Accept-Language header provided.

Kind: inner method of Hypertonic

ParamTypeDescription
friendsanye.g. 'leaderboard'

Hypertonic~getActivityLogsList() ⇒ Promise

Get Activity Logs List

The Get Activity Logs List endpoint retrieves a list of a user's activity log entries before or after a given day with offset and limit using units in the unit system which corresponds to the Accept-Language header provided.

Kind: inner method of Hypertonic

Hypertonic~getActivityTCX(logId) ⇒ Promise

Get Activity TCX

Note: Since this is a beta feature, Fitbit may need to make backwards incompatible changes with less than 30 days notice.

The Get Activity TCX endpoint retrieves the details of a user's location and heart rate data during a logged exercise activity.

The Training Center XML (TCX) is a data exchange format that contains GPS, heart rate, and lap data, when it is available for the activity. The TCX MIME type is application/vnd.garmin.tcx+xml.

Kind: inner method of Hypertonic

ParamType
logIdany

Hypertonic~getBodyFatLogs(from, to) ⇒ Promise

Get Body Fat Logs

The Get Body Fat Logs API retrieves a list of all user's body fat log entries for a given day in the format requested. Body fat log entries are available only to authorized user. If you need to fetch only the most recent entry, you can use the Get Body Measurements endpoint.

Kind: inner method of Hypertonic

ParamType
fromany
toany

Hypertonic~getBodyWeightLogs(from, to) ⇒ Promise

Get Weight Logs

The Get Weight Logs API retrieves a list of all user's body weight log entries for a given day using units in the unit systems which corresponds to the Accept-Language header provided. Body weight log entries are available only to authorized user. Body weight log entries in response are sorted exactly the same as they are presented on the Fitbit website.

Kind: inner method of Hypertonic

ParamType
fromany
toany

Hypertonic~getSleepLogs(from, to) ⇒ Promise

Get Sleep Logs

The Get Sleep Logs by Date endpoint returns a summary and list of a user's sleep log entries (including naps) as well as detailed sleep entry data for a given day.

Kind: inner method of Hypertonic

ParamType
fromany
toany

Hypertonic~getSummary(date) ⇒ Promise

Get Daily Activity Summary

The Get Daily Activity Summary endpoint retrieves a summary and list of a user's activities and activity log entries for a given day in the format requested using units in the unit system which corresponds to the Accept-Language header provided.

Kind: inner method of Hypertonic

ParamType
dateany

Hypertonic~getWaterLogs(date) ⇒ Promise

Get Water Logs

The Get Water Logs endpoint retrieves a summary and list of a user's water log entries for a given day in the format requested using units in the unit system that corresponds to the Accept-Language header provided. Water log entries are available only to an authorized user.

Kind: inner method of Hypertonic

ParamType
dateany

Hypertonic~getFoodLogs(date) ⇒ Promise

Get Food Logs

The Get Food Logs endpoint returns a summary and list of a user's food log entries for a given day in the format requested.

Kind: inner method of Hypertonic

ParamType
dateany

Hypertonic~getBodyTimeSeries(bodyMetric, from, to) ⇒ Promise

Get Body Time Series

The Get Body Time Series API returns time series data in the specified range for a given resource in the format requested using units in the unit systems that corresponds to the Accept-Language header provided.

Kind: inner method of Hypertonic

ParamType
bodyMetricany
fromany
toany

Hypertonic~getTimeSeries(activity, from, to) ⇒ Promise

Get Activity Time Series

The Get Activity Time Series endpoint returns time series data in the specified range for a given resource in the format requested using units in the unit system that corresponds to the Accept-Language header provided.

Kind: inner method of Hypertonic Returns: Promise - Activity time series data.

ParamTypeDescription
activityanyname of activity e.g. steps, heartrate
fromanyfrom date
toanyto date

How can I get my token?

A working example can be found in the example directory.

OAuth 2

First off, to be able to authenticate and get your access token, you will need a client id and secret from Fitbit. This example uses simple-oauth2. The JSON object below contains the necessary information needed to authenticate.

{
    "credentials": {
        "client": {
            "id": "<FROM_FITBIT>",
            "secret": "<FROM_FITBIT>"
        },
        "auth": {
            "tokenHost": "https://api.fitbit.com",
            "tokenPath": "/oauth2/token",
            "authorizeHost": "https://www.fitbit.com",
            "authorizePath": "/oauth2/authorize"
        }
    },
    "settings": {
        "scopes": "activity profile settings social heartrate sleep",
        "expires_in": 604800
    }
}
OptionDescription
client idIdentifier for your application given by the OAuth server.
client secretOnly known to the application and the authorisation server.
scopesSpecify API access granted to the user. Must be a space delimited string.
const auth = oauth2.create(fitbit.credentials);
const authUrl = auth.authorizationCode
                        .authorizeURL({ scope: fitbit.settings.scopes });

Fitbit Token Object

Once you authenticate with Fitbit you will receive an object which looks like the below code snippet. hypertonic accepts the access_token value (e.g. newhypertonic(token.access_token)).

{
    "token": {
        "access_token": "",
        "expires_in": 604800,
        "refresh_token": "",
        "scope": "",
        "token_type": "Bearer",
        "user_id": "",
        "expires_at": ""
    }
}
1.3.0

6 years ago

1.2.1

6 years ago

1.1.1

6 years ago

1.0.1

6 years ago