withings-lib
Withings API library for node.js
Install
$ npm install --save withings-lib
Usage
var express = var config = var app = var Withings = ;var cookieParser = ;var session = ; app;app;app; // OAuth flowapp; // On return from the authorizationapp; // Display today's steps for a userapp
Client API
Activity Measures
Withings.getDailySteps(date, callback)
The date is a Date
object, and the callback is of the form function(err, data)
. The data
is the integer number of steps the user has taken today.
Withings.getDailyCalories(date, callback)
The date is a Date
object, and the callback is of the form function(err, data)
. The data
is the integer number of calories the user has consumed today.
Body Measures
Body measures return measurement group arrays with the following form. Measures are displayed in scientific notation.
Withings.getWeightMeasures(startDate, endDate, callback)
The dates are Date
objects, and the callback is of the form function(err, data)
. The data
is an array of measurement groups.
Withings.getPulseMeasures(startDate, endDate, callback)
The dates are Date
objects, and the callback is of the form function(err, data)
. The data
is an array of measurement groups.
Sleep Summary
Sleep summaries return series arrays with the following form. Durations are displayed in seconds.
Withings.getSleepSummary(startDate, endDate, callback)
The dates are Date
objects, and the callback is of the form function(err, data)
. The data
is an array of measurement groups.
Notifications
For notifications requests, parameters should be used as follows:
-
callbackUrl
- The URL the API notification service will call. This URL will be used as a key whenever one needs to list it or revoke it.
WBS API notifications are merely HTTP POST requests to this URL (such as http://www.yourdomain.net/yourCustomApplication.php?userid=123456&startdate=1260350649 &enddate=1260350650&appli=44).
Those requests contain startdate and enddate parameters (both are integers in EPOCH format) and the userid it refers to. It is up to the targeted system to issue a measure/getmeas request using both figures to retrieve updated data.
The payload for each
appli
type is as follows:- 1 (Body Scale) : userid=123545&startdate=1411002541&enddate=1411002542
- 4 (Blood pressure monitor) : userid=123545&startdate=1411002541&enddate=1411002542
- 16 (Withings pulse) : userid=123545&date=2014-06-08
- 44 (Sleep monitor) : userid=123545&startdate=1411002541&enddate=1411003542
- The URL the API notification service will call. This URL will be used as a key whenever one needs to list it or revoke it.
WBS API notifications are merely HTTP POST requests to this URL (such as http://www.yourdomain.net/yourCustomApplication.php?userid=123456&startdate=1260350649 &enddate=1260350650&appli=44).
Those requests contain startdate and enddate parameters (both are integers in EPOCH format) and the userid it refers to. It is up to the targeted system to issue a measure/getmeas request using both figures to retrieve updated data.
The payload for each
-
comment
- The comment string is used as a description displayed to the user when presenting the notification setup.
-
appli
- The value for this parameter is a number, which corresponds to:
- 1: Weight
- 4: Heart Rate, Diastolic pressure, Systolic pressure, Oxymetry
- 16: Activity Measure ( steps, calories, distance, elevation)
- 44: Sleep
- The value for this parameter is a number, which corresponds to:
Withings.createNotification(callbackUrl, comment, appli, cb)
A notification lets your system be informed every time new data is available for a user. Withings will call a provided url every time the user syncs its withings device with its account. Returns the status of the POST request.
Withings.getNotification(callbackUrl, appli, cb)
Allows third party applications to check whether the notification service was previously subscribed on a specific user and to retrieve the subscription expiration date. Returns the notification expiration date and comment.
Withings.listNotifications(appli, cb)
List notification configurations for a user. Returns an array of notifications with expiration date and comment.
Withings.revokeNotification(callbackUrl, appli, cb)
Allows third party applications to revoke a previously subscribed notification. This will disable the notification feature between the WBS API and the specified applications for a user. Returns the status of the GET request.
Contributing
Contributions are welcome. See issues here.
Release Notes
See release notes here.
License
Licensed under Apache 2.0.