📓 Implementation Example
Let's look at a complete scenario with a user.
At first, we start by activating the device and we pass 80kg as the baseline weight.
Endpoint Details:
- Endpoint:
https://wbsapi.withings.net/v2/user
- Method:
POST
{
"action": "activate",
"client_id": "yourClientID",
"mailingpref": 1,
"birthdate": "1985-06-15",
"nonce": nonce,
"signature": signature,
"measures": '[{"value":190,"unit":-2,"type":4},{"value":10,"unit":0,"type":1}]',
"gender": 0,
"preflang": "en_US",
"unit_pref": '{"weight":1,"height":6,"distance":6,"temperature":11}',
"email": "user@example.com",
"timezone": "America/New_York",
"shortname": "JDE",
"mac_addresses": ["00:1A:2B:3C:4D:5E"],
}
We get our authorization code, and we can exchange it for an access and refresh token.
Then, using our tokens, we can pull the measurement and check the probability:
{
"status": 0,
"body": {
"updatetime": 1712722989,
"timezone": "America/New_York",
"measuregrps": [
{
"grpid": 5423702714,
"attrib": 0,
"date": 1712722953,
"created": 1712722989,
"modified": 1712722989,
"category": 1,
"deviceid": 14546187,
"hash_deviceid": "7df35c0a18c61a7009072621879658d91467dcb3",
"probability": 100,
"measures": [
{
"value": 75232,
"type": 1,
"unit": -3,
"algo": 218236163,
"fm": 3
}
],
"modelid": 17,
"model": "Body Comp Pro",
"comment": null
}
]
}
}
As expected, we get a probability of 100.
Now, lets say that the user step on the scale for the first time.
We will receive a notification, and we can pull the first "real measurement":
{
"status": 0,
"body": {
"updatetime": 1712722989,
"timezone": "America/New_York",
"measuregrps": [
{
"grpid": 5423702714,
"attrib": 0,
"date": 1712722953,
"created": 1712722989,
"modified": 1712722989,
"category": 1,
"deviceid": 14546187,
"hash_deviceid": "7df35c0a18c61a7009072621879658d91467dcb3",
"probability": 100,
"measures": [
{
"value": 75232,
"type": 1,
"unit": -3,
"algo": 218236163,
"fm": 3
}],
"modelid": 17,
"model": "Body Comp Pro",
"comment": null
}]
}
}
We have a probability of 92 for this measurement.
A good pratice is to always confirm the first measurement to ensure that the baseline weight is correct.
In order to do so we recommend you to prompt the user with a message in your application or to send him a push notification/sms.
Once the user confirmed the measurement on your side, we can perform the request to the Withings API:
{
"access_token": "YourAccessToken",
"action": "confirm",
"grpid": "12345",
"is_confirmed": 1
}
Now, we should get high probabilty for the next measurements if it's the same user using the scale.
Let's say that someone else use the scale to weight himself.
We will receive a notification and we can pull the measurement:
{
"status": 0,
"body": {
"updatetime": 1712722989,
"timezone": "America/New_York",
"measuregrps": [
{
"grpid": 5423702714,
"attrib": 0,
"date": 1712722953,
"created": 1712722989,
"modified": 1712722989,
"category": 1,
"deviceid": 14546187,
"hash_deviceid": "7df35c0a18c61a7009072621879658d91467dcb3",
"probability": 23,
"measures": [
{
"value": 75232,
"type": 1,
"unit": -3,
"algo": 218236163,
"fm": 3
}],
"modelid": 17,
"model": "Body Comp Pro",
"comment": null
}]
}
}
We get a low probability as expected.
Once we know this measurement doesn't belong to the user with can do the request to reject the measurement:
{
"access_token": "YourAccessToken",
"action": "confirm",
"grpid": "12345",
"is_confirmed": 0
}
This will improve the algorithm for future measurements.