Enias Cailliau
Enias Cailliau

Reputation: 486

Using aggregate call Google Fit REST API

I am trying to use the Google Health API with a REST API. I am aware there is an API available for Android but I am trying to port that behavior to a back end.

I am playing around in the Oauth playground; I am trying to get a aggregated query. I've tried many things but none of them return anything (only get errors) There is no example featured on the google website itself. Anyone has experience with this API?

I have found a few examples here on stackoverflow but none of them conclude with a solution or a full query that can fit as an example. Here and Here

If I just could get a working aggregate example I would work from there.

Here is my request to https://www.googleapis.com/fitness/v1/users/me/dataset:aggregate:

    {
  "startTimeMillis": 1451647796000,
  "endTimeMillis": 1458127796000,
  "aggregateBy": [
    {
      "dataTypeName": "com.google.height"
    }
  ],"bucketByTime": {
    "period": {
      "type": "day",
      "value": 1,
      "timeZoneId": "org.joda.timezone.DateTimeZone"
    }
  }
}

Response:

{
  "error": {
    "code": 400, 
    "message": "Bad Request", 
    "errors": [
      {
        "domain": "global", 
        "message": "Bad Request", 
        "reason": "invalidArgument"
      }
    ]
  }
}

Upvotes: 3

Views: 1272

Answers (1)

Max
Max

Reputation: 629

You forgotten "durationMillis" field on "bucketByTime" and "dataSourceId" on "aggregateBy".

Timezone syntax is like "America/Los_Angeles" not "org.joda.timezone.DateTimeZone". You can see this strings on http://joda-time.sourceforge.net/timezones.html

Upvotes: 2

Related Questions