# Get Fitbit Device 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.

Device data (opens new window) contain details information about the devices paired to a user's account. In Fitbitter, a datapoint is expressed by the FitbitDeviceData model. Fitbitter fetches a simplified version of Device data (opens new window) as described by Fitbit. In particular, an instance of FitbitDeviceData has the following fields:

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

  /// The device id.
  String? deviceId;

  /// The current battery level of the device (can be High, Medium, Low, or Empty).
  String? batteryLevel;

  /// The version of the device.
  String? deviceVersion;

  /// The type of the device (can be TRACKER or SCALE).
  String? type;

  /// The date when the device was synched the last time.
  DateTime? lastSyncTime;

For example:

FitbitDeviceData(userID: 7ML2XV, deviceId: 1085158180, deviceVersion: Versa 2, batteryLevel: Medium, lastSyncTime: 2022-05-09 13:17:50.000, type: TRACKER, )

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

# Step 1: Instanciate a manager

First, you need to instanciate a FitbitDeviceDataManager

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

# Step 2: Create the request url

Then, you have to create a url object, FitbitDeviceAPIURL as:

    FitbitDeviceAPIURL fitbitDeviceApiUrl = FitbitDeviceAPIURL.withCredentials(fitbitCredentials: fitbitCredentials);

# Step 3: Get the data

Finally you can obtain the Fitbit Device data using

    List<FitbitDeviceData> fitbitDeviceData = await fitbitDeviceDataManager.fetch(fitbitDeviceApiUrl);