# Get Heart Rate Variability Data

TIP

This guide assumes that your app has already been authorized and the snippet of code that I will show you can access to a valid FitbitCredentials instance, here called fitbitCredentials, the Fitbit OAuth 2.0 client ID, here called clientID, and the Fitbit client secret, here called clientSecret.

Heart Rate Variability data (opens new window) contain details about a user's Heart Rate Variability data. In Fitbitter, a datapoint is expressed by the FitbitHeartRateVariabilityData model. In particular, an instance of FitbitHeartRateVariabilityData has the following fields:

  /// The user encoded id.
  String? userID;

  /// The date of monitoring of the data.
  DateTime? dateOfMonitoring;

  /// The Root Mean Square of Successive Differences (RMSSD) between heart beats. It measures short-term variability in the user’s daily heart rate in milliseconds (ms).
  double? dailyRmssd;

  // The Root Mean Square of Successive Differences (RMSSD) between heart beats. It measures short-term variability in the user’s heart rate while in deep sleep, in milliseconds (ms).
  double? deepRmssd;

An example is:

FitbitHeartRateVariabilityData(userID: 7ML2XV, dateOfMonitoring: 2022-05-08 00:00:00.000, dailyRmssd: 45.0, deepRmssd: 34.4,)

Information about the user's Heart Rate Variability data can be obtained in three steps:

# Step 1: Instanciate a manager

First, you need to instanciate a FitbitHeartRateVariabilityDataManager

    FitbitHeartRateVariabilityDataManager fitbitHeartRateVariabilityDataManager = FitbitHeartRateVariabilityDataManager(
        clientID: '<OAuth 2.0 Client ID>',
        clientSecret: '<Client Secret>',
    );

# Step 2: Create the request url

Then, you have to create a url object, FitbitHeartRateVariabilityAPIURL to fetch the Heart Rate Variability data as:

    FitbitHeartRateVariabilityAPIURL fitbitHeartRateVariabilityAPIURL = FitbitHeartRateVariabilityAPIURL.day(
                                    date: DateTime.now(),
                                    fitbitCredentials: fitbitCredentials,
                                  );

where date is the day you want to fetch FitbitHeartRateVariabilityData from and fitbitCredentials is the FitbitCredentials instance obtained during the authentication step.

TIP

For the complete list of possible FitbitHeartRateVariabilityAPIURL, defined for different time ranges, please refer to the API Doc (opens new window).

# Step 3: Get the data

Finally you can obtain the Heart Rate Variability data using

    List<FitbitHeartRateVariabilityData> fitbitHeartRateVariabilityData = await fitbitHeartRateVariabilityDataManager.fetch(fitbitHeartRateVariabilityAPIURL);