Cancel
Showing results for 
Show  only  | Search instead for 
Did you mean: 

API endpoints/versions - sleep stages

Hi,

 

I am currently working on a project as part of my degree in engineering.
I am trying to get my sleep stage data. So far I have managed to use the API to access my sleep data, but I am getting an output with "1","2",or "3" for every minute. I understand that these number relate to "restless,asleep,awake".
What I am trying to get is specific sleep stage data, such as REM sleep/sleep stages.
From what i have read online, I see that this has something to do with endpoints. looks like I'm using an old version or something.
I would greatly appreciate some help.

 

Thank you

Best Answer
0 Votes
3 REPLIES 3

Hi @AmitLengineer,

 

Welcome to the forums!

 

It sounds like you're using the deprecated v1 Sleep endpoints. You can find our v1.2 endpoints that use Sleep Stages here. Additionally, you can find more information on how to interpret the sleep stage data returned by the endpoints here, as it may be a bit confusing at first.

 

Hope this helps. Let me know if you have any questions.

Best Answer
0 Votes

Hi John, thanks for the quick reply.

 

I'm not sure as to how to control which endpoint i'm using. From the information in the link you posted and the output i'm currently getting, It does indeed look like I'm using the v1 endpoint.

 

From the sleep logs API reference in the website:

"This endpoint supports two kinds of sleep data:

  •  stages: Levels data is returned with 30-second granularity. 'Sleep Stages' levels include deep, light, rem, and wake.
  • classic: Levels data returned with 60-second granularity. 'Sleep Pattern' levels include asleep, restless, and awake."

 

So currently I'm getting the "classic" response, and I would like to get the "stages" response.

Any idea what i need to change in my code to do that?

 

This is the part of my code which requests sleep data (I'm using Oauth2 and the fitbit library in python):

OneDate = pd.datetime(year=2020,month=12,day=28)

sleepData = auth2_client.get_sleep(date=oneDate)

 

Thanks for the help!

Best Answer
0 Votes

@AmitLengineer You'll need to change the version of your endpoints from /1/user to /1.2/user. For example

GET https://api.fitbit.com/1/user/[user-id]/sleep/date/[date].json (deprecated)
GET https://api.fitbit.com/1.2/user/[user-id]/sleep/date/[date].json

 

"Stages" and "Classic" data will be returned depending on the device paired to the account or the availability of the data collected from the sleep log, not your code. If the device worn by the user does not support "Stages", then "Classic" data will be returned. The device paired to the account must be heart rate enabled in order to received sleep stage data.

 

"Classic" data will be returned if:

  • If you slept in a position that prevented your device from getting a consistent heart-rate reading or wore it too loosely. For best results, wear your device higher on your wrist (about 2-3 finger widths above your wrist bone). The band should feel secure but not too tight.
  • If you used the Begin Sleep Now option in the Fitbit app (instead of simply wearing your device to bed). For more information on automatic sleep tracking, see How do I track my sleep with my Fitbit device?
  • If you slept for less than 3 hours.
  • If your device’s battery is critically low

Help Article: What should I know about Sleep Stages?

 

I hope this helps. Let me know if you have any additional questions.

Best Answer
0 Votes