0

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

SORoss
  • 157
  • 1
  • 1
  • 10
  • How are you calling the API are you using curl or PHP or something like that? – CodingLumis Jan 06 '22 at 09:14
  • I'm using PowerShell. – SORoss Jan 06 '22 at 09:20
  • Could you post the command you are running in PowerShell (obviously with your access token obscured). TBH, I just a had a go at doing a request myself and I get a 2554 Not Implemented response from the server which according to Withings' documentation means the service doesn't exist! – CodingLumis Jan 06 '22 at 09:35
  • It is quite possible that the devices I have don't collect HR data so maybe that is the reason for the response. However, it is accepting my HTTP message so I guess whatever I'm doing different to you means that I'm at least getting the parameters formatted correctly. – CodingLumis Jan 06 '22 at 09:37
  • OK I got the data fine when I switched to using curl commands from WSL so at least their examples work. – CodingLumis Jan 06 '22 at 09:47
  • Invoke-RestMethod -Method 'Post' -Headers $Headers -Body "action=getmeas&&meastypes=11&category=1&startdate=1641168000&enddate=1641254399&offset=offset&lastupdate=int" -Uri 'https://wbsapi.withings.net/measure' This seems to get a successful response, but doesn't contain actual data. curl --header "Authorization: Bearer XXXXXXXXXXXXXXXXXXXXXXXXXXXXX" --data "action=getmeas&meastypes=11&category=1&startdate=1641168000&enddate=1641254399&offset=offset&lastupdate=int" 'https://wbsapi.withings.net/measure' – SORoss Jan 06 '22 at 10:34
  • Well if you get a successful response but your measurement group array is empty then there isn't any data to return for the time range you specified. Are you sure there is HR data there to begin with? – CodingLumis Jan 06 '22 at 11:35
  • That only works with CURL but not PowerShell, I should say. I have a Steel HR, so it should be there. It certainly shows up in Health Mate. – SORoss Jan 06 '22 at 11:57

1 Answers1

0

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":[]
    }
}
CodingLumis
  • 594
  • 2
  • 22