04-13-2021 05:49
04-13-2021 05:49
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
04-13-2021 14:56
04-13-2021 14:56
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.
04-14-2021 00:52
04-14-2021 00:52
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:
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!
04-14-2021 13:52
04-14-2021 13:52
@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:
Help Article: What should I know about Sleep Stages?
I hope this helps. Let me know if you have any additional questions.