Subscribe to Notifications
To implement the notification system, you must subscribe to it with an access_token.
You will have to specify the endpoint (callbackurl) you want Withings to send the notifications to and for which data category you want to receive notification.
Once subscribed, your system will receive notifications when relevant data is available and fetch the new data based on the category.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
const axios = require('axios');
const accessToken = 'your_access_token'; // Replace with your actual access token
const subscribe = async () => {
const data = {
action: 'subscribe',
callbackurl: 'https://callbackurl.com/',
appli: 1,
comment: 'My comment'
};
try {
const response = await axios.post('https://wbsapi.withings.net', data, {
headers: {
Authorization: `Bearer ${accessToken}`,
'Content-Type': 'application/x-www-form-urlencoded'
}
});
console.log('Response:', response.data);
} catch (error) {
console.error('Error:', error);
}
};
// Call the async function
subscribe();