08-13-2021 05:41
08-13-2021 05:41
I'm drafting my requirements specification document using Fitbit in a research study to monitor sleep.
I want to ask our technical team to use the get sleep logs API call on a daily basis so we can measure participant compliance with the study protocol - e.g., are they wearing their Fitbit at night like we've asked them to?
Calculating wear time at night is complicated, so I'm considering using isMainSleep data element as a simplifying factor. If we pull the logs and get isMainSleep = true, it means they've at least logged something.
What does the get sleep logs API call look like if someone hasn't worn their Fitbit that night? Does the whole query return null or does each data element return as null? I need to tell our tech team what to look for as a negative result!
Thanks!
GET https://api.fitbit.com/1.2/user/[user-id]/sleep/date/[date].json
08-20-2021 12:19
08-20-2021 12:19
Hi @cwebster_nymbly,
If a sleep log isn't actually logged (automatically or manually) as in the user just did not wear the device to sleep, nothing will show for that day.
However, if a Fitbit user did wear the device to sleep, but the device did not have a strong heart rate reading, or low battery, you might be provided with a classic sleep log rather than a log with sleep stages. For more information on how devices track sleep, see: https://help.fitbit.com/articles/en_US/Help_article/2163.htm#
In the endpoint you provided, you can determine if the log was "classic" or "stages" by looking for the following element:
"type": "classic"
I hope this helps. Let me know if you have any additional questions.
08-22-2021 13:52
08-22-2021 13:52
Thanks @JohnFitbit ! A follow-up question. Is the data element isMainSleep returned in a "classic" sleep log?
Or is that element only returned in a "stages" sleep log?
Thanks!
08-26-2021 16:21
08-26-2021 16:21
@cwebster_nymbly I believe that the isMainSleep element is returned for both sleep types. Are you only seeing this element in one type of sleep?