Skip to main content

Fetch data after a notification

You just received a webhook. Here's how to turn that POST into a Data API call and pull the fresh measurement.

What you'll need
  • The OAuth access token you stored for the user
  • The notification payload your endpoint just received
  • The Data API endpoint for the matching appli category — see the catalog

Walk through

  1. 1

    Parse the notification

    Withings sends an application/x-www-form-urlencoded POST to your endpoint.

    Three fields matter: userid tells you which user the measurement belongs to, appli indicates which data category was updated — and therefore which endpoint to call next — and startdate/enddate mark the time window covered by the change.

  2. 2

    Look up the access token

    Use userid to fetch the OAuth access token you stored for this user at signup.

    Access tokens are short-lived, so check the expiry and refresh with the refresh token if needed — otherwise the Data API rejects the call with 401 Unauthorized.

  3. 3

    Pick a time window

    You have two options.

    Reusing the payload's startdate/enddate targets that single measurement precisely — useful when you only want the data point that triggered the notification.

    For ongoing sync, we recommend lastupdate instead: pass the timestamp of your last successful fetch and the Data API returns everything created or modified since, including any updates you missed if a notification was lost.

    Compute lastupdate→
  4. 4

    Call the matching endpoint

    Each appli category maps to a specific Data API endpoint — for example, weight notifications (appli=1) are served by the measure service, sleep summaries by sleep.

    POST to the matching endpoint with the access token and your chosen time window in the request body.

    Browse all categories→

Working example

The snippet calls getmeas on the measure service — the endpoint for weight (appli=1). For other categories, swap to the service listed in the catalog.

const axios = require('axios');

const accessToken = 'your_access_token';  // Replace with your actual access token

const getMeasurements = async () => {
  const data = {
    action: 'getmeas',
    startdate: 1727825531,  // Replace with your actual startdate
    enddate: 1728171131     // Replace with your actual enddate
  };

  try {
    const response = await axios.post('https://wbsapi.withings.net/measure', 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
getMeasurements();