Repository navigation
Sleep stages data may require v1.2 API endpoint #128
Description
Activity
🤔 @DanWebster Maybe we should make the version specifiable so people could use the version they want?
Would it be better to make this set-able when initializing the OAuth2 or expose this for the different endpoints that feed into
make_request?I will check today if making a 1.2 call breaks a few of the more canonical datasets and respond back here. Thanks for the quick response, btw.
Oh that's interesting, so you could specify a different version depending upon the endpoint. Maybe you could specify a default version to use for all requests when you create the fitbit client, but then you could also override it for a specific request
@DanWebster Thanks for checking that 👍
Can confirm that hardcoding in
API_VERSION = 1.2(line 23, line 190 in api.py) does update the intraday sleep data (see example output below) but still maintains other data type integrity (I checked intraday HR data but did not do an exhaustive test of all API calls).I think that this means being able to specify API version as a parameter when setting up the oauth client (rather than in each specific
make_request call) would be perfect and provide flexibility as the API versions update. Thanks!!{'dateTime': '2018-02-18T06:00:00.000', 'level': 'wake', 'seconds': 30}, {'dateTime': '2018-02-18T06:50:30.000', 'level': 'wake', 'seconds': 30}, {'dateTime': '2018-02-18T07:14:00.000', 'level': 'wake', 'seconds': 60}], 'summary': {'deep': {'count': 4, 'minutes': 42, 'thirtyDayAvgMinutes': 44}, 'light': {'count': 22, 'minutes': 331, 'thirtyDayAvgMinutes': 229}, 'rem': {'count': 7, 'minutes': 68, 'thirtyDayAvgMinutes': 84}, 'wake': {'count': 24, 'minutes': 57, 'thirtyDayAvgMinutes': 47}}},```@DanWebster Awesome, thank you for the testing!
@DanWebster Thanks for that. I have hard coded the api version as you mentioned to get detailed sleep stages. Have you noticed any breaks on the code from that change?
@Dannie1G Seems to work for the endpoints I am looking at (admittedly not exhaustive) with no breaks.
Reacted by Dannie and Oscar GarnicaI'm able to get the sleep data assuming that I know the date. I had to change the hardcoded API version just the same as this issue. Regarding additional endpoints, I am trying to get a list of nights the user has slept : https://dev.fitbit.com/build/reference/web-api/sleep/ - Get Sleep Logs List using the GET https://api.fitbit.com/1.2/user/-/sleep/list.json endpoint. I am not able to figure out from the documentation if getting a list of nights is supported by orcas-fitbit.
@ANNCHAN not sure what kind of list you want. I’ve written a little script and posted as jupyter notebook (https://github.com/Dannie1G/python-fitbit/blob/master/Fitbit_APIv12DataCollection_gh.ipynb). In one I collect my sleep stages for each night as separate csv, and in another I collect sleep stats for dates that fall in a specific period of time. Have a look and let me know if you need help following it.
@Dannie1G Your code assumes that you know the last date at which you want to stop from the current date.
Example : >> last_record = datetime.date(2018, 4, 14) --> In [10].
Fitbit allows you to do this in v1.2 :
GET https://api.fitbit.com/1.2/user/-/sleep/list.json?beforeDate=2017-03-27&sort=desc&offset=0&limit=1
which basically gives you all sleep records before a certain date. For example if you needed all the sleep records before today you could just do a datetime.now() in your code and construct the above string. python-fitbit does not yet support https://api.fitbit.com/1.2/user/-/sleep/list.json endpoint. It should be simple. I'm just making a method like get_sleep(date=date) and instead calling it get_sleep_before(date=date) to support this end-point. Not sure if I should submit a PR once I do this.@aanchan I see.. yeah that makes sense, it could be handy for others PR sounds reasonable
is it necessary to hardcode the API_VERSION? why not do
authd_client.API_VERSION = 1.2Reacted by OndrejBakan, Albert Jonathan, Salvador Moreno Gutiérrez, Marina, jakemiller13, TungHo Lin(Dennis) and Daniel Woffinden@aanchan did you ever decide to submit a PR for this? I just ran into this issue and it seems a bit more pertinent now that Fitbit has deprecated the 1.0 endpoints: https://dev.fitbit.com/build/reference/web-api/sleep-v1/
Reacted by A. M Manzano Kharman- added a commit that references this issue
on Mar 14, 2021
I have noticed that the data coming back from the fitbit.sleep() doesn't return the same format as specified in the current fitbit docs.
In looking through, it looks like most of the endoints are drawing from the Version 1 of the API (
GETcalls using 1 before theuseras per below)GET https://api.fitbit.com/1/user/[user-id]/activities/date/[date].jsonBut for the newest Sleep data, they look to be going from a 1.2 version
GET https://api.fitbit.com/1.2/user/[user-id]/sleep/date/[date].jsonapi.py specifies API_VERSION=1; I haven't been using fitbit data until a few days ago so I am unsure whether this has a historical precedent for API differences between types and keeping backwards compatibility or not.