Support for the legacy Fitbit Web API ends on September 30, 2026
Important: Support for the legacy Fitbit Web API ends on September 30, 2026. After this date the API will continue to operate, but Google will no longer fix bugs or provide API support. On October 30, 2026, the Fitbit Web API will be turned off and will no longer function or sync data to or from Fitbit users. To continue accessing data for your users after this date, migrate to the Google Health API.
Sleep API
chevron down
 

Sleep API

Variable: sleep

Type: Sleep

Sleep

String: ISleep | undefined

The Sleep API allows applications to determine whether the user is currently sleeping or not, and be notified when the user goes to sleep and wakes up.

This API provides a reliable update mechanism which is automatically deactivated when the device display is off.

The access_sleep permission must be granted, else this module will be empty.

import { me as appbit } from "appbit";

if (!appbit.permissions.granted("access_sleep")) {
   console.log("We're not allowed to read a users' sleep!");
}

import sleep from "sleep";

if (sleep) {
  sleep.addEventListener("change", () => {
     console.log(`User sleep state is: ${sleep.state}`);
   });
} else {
   console.warn("Sleep API not supported on this device, or no permission")
}

Interface: ISleep

The Sleep object describes the current sleep state of the user and provides events that report changes in sleep state.

Properties

onchange

((this: Sleep, event: Event) => any) or undefined

Event handler for the change event emitted by the sleep service.

readonly state

"unknown" or "awake" or "asleep"

Describes whether the user is asleep or not, or if the current sleep state is not known.