# Get Heart 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 the Fitbit user id, here called userID, the Fitbit OAuth 2.0 client ID, here called clientID, and the Fitbit client secret, here called clientSecret.

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

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

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

  /// The calories spent out of active range during the [dateOfMonitoring].
  double? caloriesOutOfRange;

  /// The minimum value of the out of active range.
  int? minimumOutOfRange;

  /// The minutes spent out of active range during the [dateOfMonitoring].
  int? minutesOutOfRange;

  /// The calories spent in the fat burn range during the [dateOfMonitoring].
  double? caloriesFatBurn;

  /// The minimum value of the fat burn range.
  int? minimumFatBurn;

  /// The minutes spent in the fat burn range during the [dateOfMonitoring].
  int? minutesFatBurn;

  /// The calories spent in the cardio range during the [dateOfMonitoring].
  double? caloriesCardio;

  /// The minimum value of the cardio range.
  int? minimumCardio;

  /// The minutes spent in the cardio range during the [dateOfMonitoring].
  int? minutesCardio;

  /// The calories spent in the peak range during the [dateOfMonitoring].
  double? caloriesPeak;

  /// The minimum value of the peak range.
  int? minimumPeak;

  /// The minutes spent in the peak range during the [dateOfMonitoring].
  int? minutesPeak;

  /// The resting heart rate during the [dateOfMonitoring].
  int? restingHeartRate;

For example:

FitbitHeartData(userID: 7ML2XV, dateOfMonitoring: 2022-05-05 00:00:00.000, caloriesOutOfRange: 2446.1926200000003, minimumOutOfRange: 30, minutesOutOfRange: 1401, caloriesFatBurn: 25.95498, minimumFatBurn: 107, minutesFatBurn: 3, caloriesCardio: 524.1107099999997, minimumCardio: 134, minutesCardio: 34, caloriesPeak: 32.89344, minimumPeak: 169, minutesPeak: 2, restingHeartRate: 52, )

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

# Step 1: Instanciate a manager

First, you need to instanciate a FitbitHeartRateDataManager

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

# Step 2: Create the request url

Then, you have to create a url object, FitbitHeartRateAPIURL, that fetches the Heart Rate data, during the desidered time range. For example:

    FitbitHeartRateAPIURL fitbitHeartRateAPIURL = FitbitHeartRateAPIURL.day(
                                    date: DateTime.now(),
                                    fitbitCredentials: fitbitCredentials,
                                  );

For the complete list of possible FitbitHeartRateAPIURL, 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 data using

    List<FitbitHeartRateData> fitbitHeartRateData = await fitbitHeartRateDataManager.fetch(fitbitHeartRateAPIURL);