Modernizing the Fitbit Developer Experience.
The Fitbit Web APIs are moving to a new, scalable infrastructure. We will be deprecating the legacy Fitbit Web API in September 2026. To ensure uninterrupted data continuity for your users, you will need to migrate your applications. Detailed migration guides are live on the Google Health API developer site.
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.