- [HTTP request](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#body.HTTP_TEMPLATE)
- [Request body](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#body.request_body)
  - [JSON representation](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#body.request_body.SCHEMA_REPRESENTATION)
- [Response body](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#body.response_body)
  - [JSON representation](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#body.BatchQueryDomainStatsResponse.SCHEMA_REPRESENTATION)
- [Authorization scopes](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#body.aspect)
- [QueryDomainStatsRequest](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#QueryDomainStatsRequest)
  - [JSON representation](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#QueryDomainStatsRequest.SCHEMA_REPRESENTATION)
- [BatchQueryDomainStatsResult](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#BatchQueryDomainStatsResult)
  - [JSON representation](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#BatchQueryDomainStatsResult.SCHEMA_REPRESENTATION)
- [Status](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#Status)
  - [JSON representation](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#Status.SCHEMA_REPRESENTATION)
- [Try it!](https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#try-it)

Executes a batch of QueryDomainStats requests for multiple domains. Returns PERMISSION_DENIED if you don't have permission to access DomainStats for any of the requested domains.

### HTTP request

`POST https://gmailpostmastertools.googleapis.com/v2/domainStats:batchQuery`

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

### Request body

The request body contains data with the following structure:

| JSON representation |
|---|
| ``` { "requests": [ { object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#QueryDomainStatsRequest`) } ] } ``` |

| Fields ||
|---|---|
| `requests[]` | ``object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#QueryDomainStatsRequest`)`` Required. A list of individual query requests. Each request can be for a different domain. A maximum of 100 requests can be included in a single batch. |

### Response body

Response message for domainStats.batchQuery.

If successful, the response body contains data with the following structure:

| JSON representation |
|---|
| ``` { "results": [ { object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#BatchQueryDomainStatsResult`) } ] } ``` |

| Fields ||
|---|---|
| `results[]` | ``object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#BatchQueryDomainStatsResult`)`` A list of responses, one for each query in the BatchQueryDomainStatsRequest. The order of responses will correspond to the order of requests. |

### 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).

## QueryDomainStatsRequest

Request message for QueryDomainStats.

| JSON representation |
|---|
| ``` { "parent": string, "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 ||
|---|---|
| `parent` | `string` Required. The parent resource name where the stats are queried. Format: domains/{domain} |
| `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. |

## BatchQueryDomainStatsResult

Represents the result of a single QueryDomainStatsRequest within a batch.

| JSON representation |
|---|
| ``` { "response": { object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/QueryDomainStatsResponse`) }, "error": { object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#Status`) } } ``` |

| Fields ||
|---|---|
| Union field `result`. The result of the individual query. `result` can be only one of the following: ||
| `response` | ``object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/QueryDomainStatsResponse`)`` The successful response for the individual query. |
| `error` | ``object (`https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#Status`)`` The error status if the individual query failed. |

## Status

The `Status` type defines a logical error model that is suitable for different programming environments, including REST APIs and RPC APIs. It is used by [gRPC](https://github.com/grpc). Each `Status` message contains three pieces of data: error code, error message, and error details.

You can find out more about this error model and how to work with it in the [API Design Guide](https://cloud.google.com/apis/design/errors).

| JSON representation |
|---|
| ``` { "code": integer, "message": string, "details": [ { "@type": string, field1: ..., ... } ] } ``` |

| Fields ||
|---|---|
| `code` | `integer` The status code, which should be an enum value of `google.rpc.Code`. |
| `message` | `string` A developer-facing error message, which should be in English. Any user-facing error message should be localized and sent in the `https://developers.google.com/workspace/gmail/postmaster/reference/rest/v2/domainStats/batchQuery#Status.FIELDS.details` field, or localized by the client. |
| `details[]` | `object` A list of messages that carry the error details. There is a common set of message types for APIs to use. |