1

I am trying to get heart points from google fit REST API. I see that heart rate data in google fit app (110 bmg) but i am getting empty data through the API.

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

BODY:

{
  "aggregateBy": [{
    "dataTypeName": "com.google.heart_rate.bpm",
    "dataSourceId": "derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes"
  }],
  "bucketByTime": { "durationMillis": 86400000 },
  "startTimeMillis": 1580533200000, // feb 01 2020
  "endTimeMillis": 1582866000000 // feb 28 2020
}

Result :

i am getting empty records like :

{
    "bucket": [ 
....
{
            "startTimeMillis": "1580619600000",
            "endTimeMillis": "1580706000000",
            "dataset": [
                {
                    "dataSourceId": "derived:com.google.heart_minutes.summary:com.google.android.gms:aggregated",
                    "point": []
                }
            ]
        },
....
    ]
}

Am i missing anything?

TheDeveloper
  • 1,127
  • 1
  • 18
  • 55

1 Answers1

3

Never mind, I got it. It took some time to update the API i guess, I had to update the body:

{
  "aggregateBy": [{
    "dataTypeName": "com.google.heart_minutes"
    //"dataSourceId": "derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes"
  }],
  "bucketByTime": { "durationMillis": 86400000 },
  "startTimeMillis": 1580533200000, // feb 01 2019
  "endTimeMillis": 1580878800000 // feb 6 2020 1582866000000 // feb 28 2020
}
TheDeveloper
  • 1,127
  • 1
  • 18
  • 55
  • "It took some time to update the API i guess, I had to update the body:" What do you mean? – Andy Turner Feb 04 '20 at 16:39
  • I synced heartrate from the app to googlefit, but it could took few minutes to fetch those synced data from REST API. – TheDeveloper Feb 05 '20 at 21:34
  • Can I ask - in your answer did it work with the `dataSourceId` commented out like that? Also where did you find the documentation for the `dataSourceId` value you used (`derived:com.google.heart_minutes:com.google.android.gms:merge_heart_minutes`)? I'm trying to get heart rate summary but have no idea what to use for data source, can't find any documentation – James Allen Nov 22 '20 at 17:10
  • @JamesAllen you can remove the commented code i.e., you can remove //datasourceid line completely. not sure where i found the document. It is hard to find proper document. i looked at blood glucose examples and after multiplr trial and errors found this solution. – TheDeveloper Dec 03 '20 at 07:21