# Class BatchRequest (1.73.0)

<button class="button button-with-icon cloud-select-dropdown__button " aria-haspopup="true">Version latest</button>

- [1.73.0 (latest)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.BatchRequest)
- [1.69.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.69.0/Google.Apis.Requests.BatchRequest)
- [1.68.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.68.0/Google.Apis.Requests.BatchRequest)
- [1.60.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.60.0/Google.Apis.Requests.BatchRequest)
- [1.59.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.59.0/Google.Apis.Requests.BatchRequest)
- [1.55.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.55.0/Google.Apis.Requests.BatchRequest)
- [1.50.0](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/1.50.0/Google.Apis.Requests.BatchRequest)

    public sealed class BatchRequest

A batch request which represents individual requests to Google servers. You should add a single service
request using the [Queue\<TResponse\>(IClientServiceRequest, OnResponse\<TResponse\>)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.BatchRequest#Google_Apis_Requests_BatchRequest_Queue__1_Google_Apis_Requests_IClientServiceRequest_Google_Apis_Requests_BatchRequest_OnResponse___0__) method and execute all individual requests using
[ExecuteAsync()](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.BatchRequest#Google_Apis_Requests_BatchRequest_ExecuteAsync). More information about the batch protocol is available in
<https://developers.google.com/storage/docs/json_api/v1/how-tos/batch>.

## Inheritance

[object](https://learn.microsoft.com/dotnet/api/system.object) \> BatchRequest

## Inherited Members

[object.Equals(object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object)) [object.Equals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.equals#system-object-equals(system-object-system-object)) [object.GetHashCode()](https://learn.microsoft.com/dotnet/api/system.object.gethashcode) [object.GetType()](https://learn.microsoft.com/dotnet/api/system.object.gettype) [object.ReferenceEquals(object, object)](https://learn.microsoft.com/dotnet/api/system.object.referenceequals) [object.ToString()](https://learn.microsoft.com/dotnet/api/system.object.tostring)

## Namespace

[Google.Apis.Requests](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests)

## Assembly

Google.Apis.dll

## Constructors

### BatchRequest(IClientService)

    public BatchRequest(IClientService service)

Constructs a new batch request using the given service. See
[BatchRequest(IClientService, string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.BatchRequest#Google_Apis_Requests_BatchRequest__ctor_Google_Apis_Services_IClientService_System_String_) for more information.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `service` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.IClientService` |

### BatchRequest(IClientService, string)

    public BatchRequest(IClientService service, string batchUrl)

Constructs a new batch request using the given service. The service's HTTP client is used to create a
request to the given server URL and its serializer members are used to serialize the request and
deserialize the response.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `service` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Services.IClientService` |
| `batchUrl` | `https://learn.microsoft.com/dotnet/api/system.string` |

## Properties

### Count

    public int Count { get; }

Gets the count of all queued requests.

| **Property Value** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.int32` |   |

## Methods

### ExecuteAsync()

    public Task ExecuteAsync()

Asynchronously executes the batch request.

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` |   |

### ExecuteAsync(CancellationToken)

    public Task ExecuteAsync(CancellationToken cancellationToken)

Asynchronously executes the batch request.

| **Parameter** ||
|---|---|
| **Name** | **Description** |
| `cancellationToken` | `https://learn.microsoft.com/dotnet/api/system.threading.cancellationtoken` Cancellation token to cancel operation. |

| **Returns** ||
|---|---|
| **Type** | **Description** |
| `https://learn.microsoft.com/dotnet/api/system.threading.tasks.task` |   |

### Queue\<TResponse\>(IClientServiceRequest, OnResponse\<TResponse\>)

    public void Queue<TResponse>(IClientServiceRequest request, BatchRequest.OnResponse<TResponse> callback) where TResponse : class

Queues an individual request.

| **Parameters** ||
|---|---|
| **Name** | **Description** |
| `request` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.IClientServiceRequest` The individual request. |
| `callback` | `https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.BatchRequesthttps://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Requests.BatchRequest.OnResponse-1` A callback which will be called after a response was parsed. |

| **Type Parameter** ||
|---|---|
| **Name** | **Description** |
| `TResponse` | The response's type. |

## Extension Method

[Utilities.ThrowIfNull\<T\>(T, string)](https://docs.cloud.google.com/dotnet/docs/reference/Google.Apis/latest/Google.Apis.Util.Utilities#Google_Apis_Util_Utilities_ThrowIfNull__1___0_System_String_)