Search code examples
restgoogle-fitheartrategoogle-fit-api

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?


Solution

  • 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.