1

I'm trying to retrieve aggregate daily heart rate summary data using the Google Fit REST API, but I'm struggling because either I'm missing something or the documentation seems to be very incomplete. I've successfully managed to retrieve aggregate daily step count by following one of the few available examples:

Request URL

https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate

Request body

{
  "aggregateBy": [{
    "dataTypeName": "com.google.step_count.delta",
    "dataSourceId": "derived:com.google.step_count.delta:com.google.android.gms:estimated_steps"
  }],
  "bucketByTime": { "durationMillis": 86400000 },
  "startTimeMillis": 1438705622000,
  "endTimeMillis": 1439310422000
}

I can't find any example for reading heart rate, so I'm trying to modify this for heart rate. I found this list of data types where it has this data type: com.google.heart_rate.summary but there isn't any information on what the dataSourceId should be. I tried just omitting it but I get this error:

no default datasource found for: com.google.heart_rate.summary

Does anybody know what I need to use for dataSourceId, or have a link to any decent documentation on data sources?

James Allen
  • 6,406
  • 8
  • 50
  • 83
  • 1
    Don't set both `dataTypeName` and `dataSourceId`: setting a specific data source id will take precedence over setting the data type. – Andy Turner Nov 24 '20 at 09:56

2 Answers2

5

For resting heart rate, I use this:

"derived:com.google.heart_rate.bpm:com.google.android.gms:resting_heart_rate<-merge_heart_rate_bpm"

For heart rate or BPM, I use this:

"derived:com.google.heart_rate.bpm:com.google.android.gms:merge_heart_rate_bpm"

For completeness, I have included the datasources that I am using below for various readings:

DATA_SOURCE = {
    "steps": "derived:com.google.step_count.delta:com.google.android.gms:merge_step_deltas",
    "dist": "derived:com.google.distance.delta:com.google.android.gms:from_steps<-merge_step_deltas",
    "bpm": "derived:com.google.heart_rate.bpm:com.google.android.gms:merge_heart_rate_bpm",
    "rhr": "derived:com.google.heart_rate.bpm:com.google.android.gms:resting_heart_rate<-merge_heart_rate_bpm",
    "sleep" : "derived:com.google.sleep.segment:com.google.android.gms:sleep_from_activity<-raw:com.google.activity.segment:com.heytap.wearable.health:stream_sleep",
    "cal" : "derived:com.google.calories.expended:com.google.android.gms:from_activities",
    "move": "derived:com.google.active_minutes:com.google.android.gms:from_steps<-estimated_steps",
    "points" : "derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes",
    "weight" : "derived:com.google.weight:com.google.android.gms:merge_weight"
}

Depending on the datasource, sometimes it will provide an array of points. You can then choose to take sum, mean, median, etc of all points in the array accordingly.

Mr L
  • 470
  • 6
  • 16
  • Thanks! This seem to work well for fetching resting heart rate data points from Google Fit. I am curious as to how you figured the datasource for resting heart rate. Just want to make sure that this is not something that Google would/can change at a later time without any notification. – praveen_85 Nov 02 '22 at 00:10
  • Just to clarify, my concern in the previous comment was mainly because resting heart rate is not exposed as a standard data type from Google Fit. – praveen_85 Nov 02 '22 at 00:27
4

You can list the data sources available for a given data type, for example :

Method

GET

Request URL

https://www.googleapis.com/fitness/v1/users/me/dataSources?dataTypeName=com.google.heart_rate.summary

Depending on what you're trying to achieve, you'll probably find a source either for com.google.heart_rate.summary or com.google.heart_rate.bpm to meet your needs, including merged sources.

Bardy
  • 2,100
  • 1
  • 13
  • 11
  • 1
    Yep, this seems to be the only way to find out - I don't understand why there isn't a documented list somewhere. Thanks – James Allen Dec 02 '20 at 12:54