---
title: "POST /{userId}/dataset:aggregate"
method: POST
path: "/{userId}/dataset:aggregate"
tags: ["users"]
---

# POST /{userId}/dataset:aggregate

`POST /{userId}/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.

## Path parameters

- `userId` string, required

## Request body

- AggregateRequest — Next id: 10
  - `startTimeMillis` string, int64 — 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.
  - `aggregateBy` AggregateBy[] — 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.
    - `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.
    - `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.
  - `bucketByTime` BucketByTime
    - `period` BucketByTimePeriod
      - `type` 'day' | 'week' | 'month'
      - `value` integer
      - `timeZoneId` string — org.joda.timezone.DateTimeZone
    - `durationMillis` string, int64 — 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.
  - `bucketByActivityType` BucketByActivity
    - `minDurationMillis` string, int64 — Specifies that only activity segments of duration longer than minDurationMillis are considered and used as a container for aggregated data.
    - `activityDataSourceId` string — The default activity stream will be used if a specific activityDataSourceId is not specified.
  - `endTimeMillis` string, int64 — 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. The maximum allowed difference between start_time_millis // and end_time_millis is 7776000000 (roughly 90 days).
  - `filteredDataQualityStandard` string[] — DO NOT POPULATE THIS FIELD. It is ignored.
  - `bucketBySession` BucketBySession
    - `minDurationMillis` string, int64 — Specifies that only sessions of duration longer than minDurationMillis are considered and used as a container for aggregated data.
  - `bucketByActivitySegment` BucketByActivity
    - `minDurationMillis` string, int64 — Specifies that only activity segments of duration longer than minDurationMillis are considered and used as a container for aggregated data.
    - `activityDataSourceId` string — The default activity stream will be used if a specific activityDataSourceId is not specified.

## Response `200`

Successful response

---

[API](https://skmtc.net/google/apis/fitness.md) · [All operations](https://skmtc.net/google/apis/fitness/llms.txt) · [OpenAPI document](https://skmtc-service-staging.skmtc.workers.dev/v1/apis/google/fitness/versions/036f4db4a779/schema)
