- [HTTP request](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domains.domainStats/query#body.HTTP_TEMPLATE)
- [Path parameters](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domains.domainStats/query#body.PATH_PARAMETERS)
- [Request body](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domains.domainStats/query#body.request_body)
  - [JSON representation](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domains.domainStats/query#body.request_body.SCHEMA_REPRESENTATION)
- [Response body](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domains.domainStats/query#body.response_body)
- [Authorization scopes](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domains.domainStats/query#body.aspect)
- [Try it!](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domains.domainStats/query#try-it)

Retrieves a list of domain statistics for a given domain and time period. Returns statistics only for dates where data is available. Returns PERMISSION_DENIED if you don't have permission to access DomainStats for the domain.

### HTTP request

`POST https://gmailpostmastertools.googleapis.com/v2/{parent=domains/*}/domainStats:query`

The URL uses [gRPC Transcoding](https://google.aip.dev/127) syntax.

### Path parameters

| Parameters ||
|---|---|
| `parent` | `string` Required. The parent resource name where the stats are queried. Format: domains/{domain} |

### Request body

The request body contains data with the following structure:

| JSON representation |
|---|
| ``` { "metricDefinitions": [ { object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/MetricDefinition`) } ], "timeQuery": { object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/TimeQuery`) }, "pageSize": integer, "pageToken": string, "aggregationGranularity": enum (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/AggregationGranularity`) } ``` |

| Fields ||
|---|---|
| `metricDefinitions[]` | ``object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/MetricDefinition`)`` Required. The specific metrics to query. You can define a custom name for each metric, which will be used in the response. |
| `timeQuery` | ``object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/TimeQuery`)`` Required. The time range or specific dates for which to retrieve the metrics. |
| `pageSize` | `integer` Optional. The maximum number of DomainStats resources to return in the response. The server may return fewer than this value. If unspecified, a default value of 10 will be used. The maximum value is 200. |
| `pageToken` | `string` Optional. The nextPageToken value returned from a previous List request, if any. If the aggregation granularity is DAILY, the page token will be the encoded date + "/" + metric name. If the aggregation granularity is OVERALL, the page token will be the encoded metric name. |
| `aggregationGranularity` | ``enum (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/AggregationGranularity`)`` Optional. The granularity at which to aggregate the statistics. If unspecified, defaults to DAILY. |

### Response body

If successful, the response body contains an instance of `https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/QueryDomainStatsResponse`.

### Authorization scopes

Requires one of the following OAuth scopes:

- `https://www.googleapis.com/auth/postmaster`
- `
  https://www.googleapis.com/auth/postmaster.traffic.readonly`

For more information, see the [Authorization guide](https://developers.google.com/workspace/guides/configure-oauth-consent).