# Sleep - Get
WARNING
The data are only available once a synchronization occured between the device and Withings servers (which might include synchronizing with Withings mobile application or via Withings Mobile SDK).
Sleep - Get (opens new window) returns sleep data captured at high frequency, including sleep stages.
In WithingsFlutter, the response object is expressed by the WithingsSleepGetData
. In particular, an instance of WithingsSleepGetData
has the following fields:
/// Response status
int? status;
/// Array of objects SeriesSleepGet
List<SeriesSleepGet>? series;
where SeriesSleepGet
object is:
/// The state of sleeping
int? state;
/// The starting datetime for the sleep state data
int? startdate;
/// The end datetime for the sleep data
int? enddate;
/// Series (Heart rate)
SeriesTimestampSleepGet? hr;
/// Series (Respiration Rate)
SeriesTimestampSleepGet? rr;
/// Series (Total snoring time)
SeriesTimestampSleepGet? snoring;
/// Series (Heart rate variability - Standard deviation of the NN over 1 minute)
SeriesTimestampSleepGet? sdnn1;
/// Series (Heart rate variability - Root mean square of the successive differences over "a few seconds")
SeriesTimestampSleepGet? rmssd;
and where SeriesTimestampSleepGet
object is:
/// Timestamp
int? timestamp;
/// Value associated to the timestamp
int? value;
TIP
For more info about the status
check the Withings API documentation Response Status (opens new window) section.
TIP
For more info about the values check the the Withings API documentation Sleep - Get (opens new window) in the Responses
➡️ body
section.
For example:
WithingsSleepGetData(status: 0, series: [SeriesSleepGet(state: 0, startdate: 1662860040, enddate: 1662860160, hr: null, rr: null, snoring: null, sdnn_1: null, rmssd: null, ), ..., SeriesSleepGet(state: 1, startdate: 1662866460, enddate: 1662867180, hr: SeriesTimestampSleepGet(series: [ObjSleepGet(timestamp: 1662866491, value: 45, ), ObjSleepGet(timestamp: 1662867098, value: 45, )], ), rr: null, snoring: null, sdnn_1: null, rmssd: null, )], )
Informations about the sleep data captured at high frequency, including sleep stages, can be obtained in three steps:
# Step 1: Instantiate a manager
First, you need to instanciate a WithingsSleepGetDataManager
WithingsSleepGetDataManager withingsSleepGetDataManager = WithingsSleepGetDataManager();
# Step 2: Create the request url
Then, you have to create a url object, WithingsSleepAPIURL.get
, that fetches the sleep data captured at high frequency, including sleep stages, given the:
startdate
as UNIX Timestamp to define the range of time of data to be retrievedenddate
as UNIX Timestamp to define the range of time of data to be retrieveddataFields
is aString
: a list of of requested data fields, separated by a commaaccess token
For example:
WithingsSleepAPIURL withingsSleepAPIURLGet =
WithingsSleepAPIURL.get(
startdate: 1662854063,
enddate: 1662900863,
dataFields: 'hr,rr,snoring,sdnn_1,rmssd',
accessToken: withingsCredentials.withingsAccessToken);
WARNING
If your input startdate
and enddate
are separated by more than 24h, only the first 24h after startdate
will be returned.
TIP
For more info about the dataFields
values check the Withings API documentation Sleep - Get (opens new window) in the Query Parameters
section.
# Step 3: Get the data
Finally you can obtain the list of the ECG recordings using
WithingsSleepGetData getsleepdata =
await withingsSleepGetDataManager.fetch(withingsSleepAPIURLGet);