James Allen
James Allen

Reputation: 7169

What data source ID to use for Google Fit REST heart rate query?

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?

Upvotes: 1

Views: 3015

Answers (2)

Mr L
Mr L

Reputation: 520

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.

Upvotes: 6

Bardy
Bardy

Reputation: 2170

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.

Upvotes: 5

Related Questions