Search code examples
withings

Withings API Body Sample


I'm trying to get data back from this Withings endpoint: https://developer.withings.com/api-reference/#operation/measure-getmeas

But every combination of things I've tried simply returns:

status body error


503 Invalid Params

This is the most recent body that isn't working: action=getmeas&meastype=meastype&meastypes=11&category=1&startdate=1641168000&enddate=1641254399

For reference: https://developer.withings.com/api-reference/#operation/measure-getmeas


Solution

  • Based on what you posted, the problem is your parameter meastype=meastype. If you remove this then it should run fine.

    Assuming you have followed the procedure to get an access token your call from PowerShell would look like this:

    Invoke-RestMethod -Method 'Post' -Headers @{ "Authorization" = "Bearer XXXXXXXXXXXXXXXXXX" } -Body "action=getmeas&meastypes=11&category=1&startdate=1641168000&enddate=1641254399" -Uri 'https://wbsapi.withings.net/measure'
    

    This will return a JSON structure as per the docs you link to in the question e.g.

    {
      "status": 0,
      "body": {
        "updatetime": "string",
        "timezone": "string",
        "measuregrps": [
          {
            "grpid": 12,
            "attrib": 1,
            "date": 1594245600,
            "created": 1594246600,
            "category": 1594257200,
            "deviceid": "892359876fd8805ac45bab078c4828692f0276b1",
            "measures": [
              {
                "value": 65750,
                "type": 1,
                "unit": -3,
                "algo": 3425,
                "fm": 1,
                "fw": 1000
              }
            ],
            "comment": "A measurement comment"
          }
        ],
        "more": 0,
        "offset": 0
      }
    }
    

    If your "measuregrps" is empty (like mine is below) then it means there is no data available for the time period you selected so either your device doesn't record that parameter or the data has not been synchronised to your Withings account.

    What I get when I run it (my device doesn't record HR):

    status body
    ------ ----
         0 @{updatetime=1641470158; timezone=Europe/London; measuregrps=System.Object[]}
    

    Another option is to use Windows Subsystem for Linux to run curl commands. You essentially get the same thing:

    curl --header "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXX" --data "action=getmeas&meastype=11&category=1&startdate=1609925332&enddate=1641461360" 'https://wbsapi.withings.net/measure'
    

    gives

    {
        "status":0,
        "body":{
            "updatetime":1641470640,
            "timezone":"Europe\/London",
            "measuregrps":[]
        }
    }