Users.dataset: aggregate

Aggregates data of a certain type or stream into buckets divided by a given type of boundary. Multiple data sets of multiple types and from multiple sources can be aggregated into exactly one bucket type per request. Try it now.

Request

HTTP request

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

Parameters

Parameter name Value Description
Path parameters
userId string Aggregate data for the person identified. Use me to indicate the authenticated user. Only me is supported at this time.

Authorization

This request requires authorization with at least one of the following scopes:

Scope
https://www.googleapis.com/auth/fitness.activity.read
https://www.googleapis.com/auth/fitness.activity.write
https://www.googleapis.com/auth/fitness.location.read
https://www.googleapis.com/auth/fitness.location.write
https://www.googleapis.com/auth/fitness.body.read
https://www.googleapis.com/auth/fitness.body.write
https://www.googleapis.com/auth/fitness.nutrition.read
https://www.googleapis.com/auth/fitness.nutrition.write
https://www.googleapis.com/auth/fitness.blood_pressure.read
https://www.googleapis.com/auth/fitness.blood_pressure.write
https://www.googleapis.com/auth/fitness.blood_glucose.read
https://www.googleapis.com/auth/fitness.blood_glucose.write
https://www.googleapis.com/auth/fitness.oxygen_saturation.read
https://www.googleapis.com/auth/fitness.oxygen_saturation.write
https://www.googleapis.com/auth/fitness.body_temperature.read
https://www.googleapis.com/auth/fitness.body_temperature.write
https://www.googleapis.com/auth/fitness.reproductive_health.read
https://www.googleapis.com/auth/fitness.reproductive_health.write

For more information, see the authentication and authorization page.

Request body

In the request body, supply data with the following structure:

{
  "startTimeMillis": long,
  "endTimeMillis": long,
  "aggregateBy": [
    {
      "dataTypeName": string,
      "dataSourceId": string
    }
  ],
  "filteredDataQualityStandard": [
    string
  ],
  "bucketByTime": {
    "durationMillis": long,
    "period": {
      "type": string,
      "value": integer,
      "timeZoneId": string
    }
  },
  "bucketBySession": {
    "minDurationMillis": long
  },
  "bucketByActivityType": {
    "minDurationMillis": long,
    "activityDataSourceId": string
  },
  "bucketByActivitySegment": {
    "minDurationMillis": long,
    "activityDataSourceId": string
  }
}
Property name Value Description Notes
startTimeMillis long The start of a window of time. Data that intersects with this time window will be aggregated. The time is in milliseconds since epoch, inclusive.
endTimeMillis long The end of a window of time. Data that intersects with this time window will be aggregated. The time is in milliseconds since epoch, inclusive.
aggregateBy[] list The specification of data to be aggregated. At least one aggregateBy spec must be provided. All data that is specified will be aggregated using the same bucketing criteria. There will be one dataset in the response for every aggregateBy spec.
aggregateBy[].dataTypeName string The data type to aggregate. All data sources providing this data type will contribute data to the aggregation. The response will contain a single dataset for this data type name. The dataset will have a data source ID of derived::com.google.android.gms:aggregated. If the user has no data for this data type, an empty data set will be returned. Note: Data can be aggregated by either the dataTypeName or the dataSourceId, not both.
aggregateBy[].dataSourceId string A data source ID to aggregate. Only data from the specified data source ID will be included in the aggregation. If specified, this data source must exist; the OAuth scopes in the supplied credentials must grant read access to this data type. The dataset in the response will have the same data source ID. Note: Data can be aggregated by either the dataTypeName or the dataSourceId, not both.
filteredDataQualityStandard[] list DO NOT POPULATE THIS FIELD. It is ignored.
bucketByTime nested object Specifies that data be aggregated by a single time interval. Mutually exclusive of other bucketing specifications.
bucketByTime.durationMillis long Specifies that result buckets aggregate data by exactly durationMillis time frames. Time frames that contain no data will be included in the response with an empty dataset.
bucketByTime.period nested object
bucketByTime.period.type string

Acceptable values are:
  • "day"
  • "month"
  • "week"
bucketByTime.period.value integer
bucketByTime.period.timeZoneId string org.joda.timezone.DateTimeZone
bucketBySession nested object Specifies that data be aggregated by user sessions. Data that does not fall within the time range of a session will not be included in the response. Mutually exclusive of other bucketing specifications.
bucketBySession.minDurationMillis long Specifies that only sessions of duration longer than minDurationMillis are considered and used as a container for aggregated data.
bucketByActivityType nested object Specifies that data be aggregated by the type of activity being performed when the data was recorded. All data that was recorded during a certain activity type (.for the given time range) will be aggregated into the same bucket. Data that was recorded while the user was not active will not be included in the response. Mutually exclusive of other bucketing specifications.
bucketByActivityType.minDurationMillis long Specifies that only activity segments of duration longer than minDurationMillis are considered and used as a container for aggregated data.
bucketByActivityType.activityDataSourceId string The default activity stream will be used if a specific activityDataSourceId is not specified.
bucketByActivitySegment nested object Specifies that data be aggregated each activity segment recorded for a user. Similar to bucketByActivitySegment, but bucketing is done for each activity segment rather than all segments of the same type. Mutually exclusive of other bucketing specifications.
bucketByActivitySegment.minDurationMillis long Specifies that only activity segments of duration longer than minDurationMillis are considered and used as a container for aggregated data.
bucketByActivitySegment.activityDataSourceId string The default activity stream will be used if a specific activityDataSourceId is not specified.

Response

If successful, this method returns a response body with the following structure:

{
  "bucket": [
    {
      "type": string,
      "startTimeMillis": long,
      "endTimeMillis": long,
      "dataset": [
        users.dataSources.datasets Resource
      ],
      "session": {
        "id": string,
        "name": string,
        "description": string,
        "startTimeMillis": long,
        "endTimeMillis": long,
        "modifiedTimeMillis": long,
        "application": {
          "packageName": string,
          "version": string,
          "detailsUrl": string,
          "name": string
        },
        "activityType": integer,
        "activeTimeMillis": long
      },
      "activity": integer
    }
  ]
}
Property name Value Description Notes
bucket[] list A list of buckets containing the aggregated data.
bucket[].type string The type of a bucket signifies how the data aggregation is performed in the bucket.

Acceptable values are:
  • "activitySegment"
  • "activityType"
  • "session"
  • "time"
  • "unknown"
bucket[].startTimeMillis long The start time for the aggregated data, in milliseconds since epoch, inclusive.
bucket[].endTimeMillis long The end time for the aggregated data, in milliseconds since epoch, inclusive.
bucket[].dataset[] list There will be one dataset per AggregateBy in the request.
bucket[].session nested object Available for Bucket.Type.SESSION
bucket[].session.id string A client-generated identifier that is unique across all sessions owned by this particular user.
bucket[].session.name string A human readable name of the session.
bucket[].session.description string A description for this session.
bucket[].session.startTimeMillis long A start time, in milliseconds since epoch, inclusive.
bucket[].session.endTimeMillis long An end time, in milliseconds since epoch, inclusive.
bucket[].session.modifiedTimeMillis long A timestamp that indicates when the session was last modified.
bucket[].session.application nested object The application that created the session.
bucket[].session.application.packageName string Package name for this application. This is used as a unique identifier when created by Android applications, but cannot be specified by REST clients. REST clients will have their developer project number reflected into the Data Source data stream IDs, instead of the packageName.
bucket[].session.application.version string Version of the application. You should update this field whenever the application changes in a way that affects the computation of the data.
bucket[].session.application.detailsUrl string An optional URI that can be used to link back to the application.
bucket[].session.application.name string The name of this application. This is required for REST clients, but we do not enforce uniqueness of this name. It is provided as a matter of convenience for other developers who would like to identify which REST created an Application or Data Source.
bucket[].session.activityType integer The type of activity this session represents.
bucket[].session.activeTimeMillis long Session active time. While start_time_millis and end_time_millis define the full session time, the active time can be shorter and specified by active_time_millis. If the inactive time during the session is known, it should also be inserted via a com.google.activity.segment data point with a STILL activity value

bucket[].activity integer Available for Bucket.Type.ACTIVITY_TYPE, Bucket.Type.ACTIVITY_SEGMENT

Try it!

Use the APIs Explorer below to call this method on live data and see the response.