[Batch processing](https://developers.google.com/google-ads/api/docs/batch-processing/overview.md.txt) provides a way to dispatch a set of
operations, which can be interdependent, to multiple services without
synchronously waiting for the operations to complete. You can use batch
processing to create and manage Performance Max campaigns.

This guide provides details specific to Performance Max campaigns when you work
with batch processing. The generic [batch processing guide](https://developers.google.com/google-ads/api/docs/batch-processing/overview.md.txt)
provides general information about batch processing, and the
[Structure requests guide](https://developers.google.com/google-ads/api/performance-max/structure-requests.md.txt) contains detailed information
about constructing requests to create or manage Performance Max campaigns.

To create a Performance Max campaign using batch processing, follow these steps:

## Create a new batch job

Follow the general batch processing [job creation step](https://developers.google.com/google-ads/api/docs/batch-processing/flow.md.txt#createjob) to
create a [`BatchJob`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJob.md.txt) resource.

## Prepare a list of mutate operations

Performance Max campaigns require operations to create several related
resources, which are detailed in the
[Structure requests guide](https://developers.google.com/google-ads/api/performance-max/structure-requests.md.txt). Create a
[`MutateOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/MutateOperation.md.txt) for each resource that should be included
in the batch job.

### `CampaignOperation` and `CampaignAssetOperation` requirements

When [brand guidelines](https://developers.google.com/google-ads/api/performance-max/create-campaign.md.txt#brand-guidelines) are enabled for a Performance Max
[`Campaign`](https://developers.google.com/google-ads/api/reference/rpc/v26/Campaign.md.txt) ([`brand_guidelines_enabled`](https://developers.google.com/google-ads/api/reference/rpc/v26/Campaign.md.txt#brand_guidelines_enabled)
defaults to `true` unless you set it to `false` or create a travel goals
campaign), you must link brand [`Asset`](https://developers.google.com/google-ads/api/reference/rpc/v26/Asset.md.txt) resources to the campaign by
using [`CampaignAsset`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignAsset.md.txt) resources.
[Local Services Performance Max](https://developers.google.com/google-ads/api/performance-max/asset-groups.md.txt#local-services-pmax) campaigns don't support
brand guidelines and omit brand [`CampaignAsset`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignAsset.md.txt) resources
(set [`brand_guidelines_enabled`](https://developers.google.com/google-ads/api/reference/rpc/v26/Campaign.md.txt#brand_guidelines_enabled) to `false` when
creating the campaign). Retail Performance Max campaigns (with a Merchant
Center feed) can omit brand [`CampaignAsset`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignAsset.md.txt) resources in the
same atomic sub-batch only when you create an assetless campaign without custom
[`AssetGroupAsset`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupAsset.md.txt) resources (other than HTML5
`MEDIA_BUNDLE` assets) or when
[`brand_guidelines_enabled`](https://developers.google.com/google-ads/api/reference/rpc/v26/Campaign.md.txt#brand_guidelines_enabled) is set to `false`.

In a batch job, create these [`CampaignAsset`](https://developers.google.com/google-ads/api/reference/rpc/v26/CampaignAsset.md.txt) resources
immediately after you create the [`Campaign`](https://developers.google.com/google-ads/api/reference/rpc/v26/Campaign.md.txt) resource itself (up to
1,000 operations total in the [atomic sub-batch](https://developers.google.com/google-ads/api/docs/batch-processing/best-practices.md.txt#atomicity-in-batch-splitting)).
The `Campaign` `create` operation (`resource_name`) and its consecutive
`CampaignAsset` `create` operations (`campaign`) must specify the same negative
[temporary ID](https://developers.google.com/google-ads/api/docs/batch-processing/temporary-ids.md.txt), and any prerequisite
[`AssetOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetOperation.md.txt) `create` operations must be placed
**before** the `Campaign` creation. If the `CampaignAsset` resources are not
created immediately after the `Campaign` resource (when brand guidelines are
enabled; see [troubleshooting](https://developers.google.com/google-ads/api/performance-max/troubleshooting.md.txt#campaigns-with-brand-guidelines-enabled)), the request
fails and returns a `CampaignError` indicating missing assets. Including the
`CampaignAsset` creation operations later in the same list of operations won't
prevent this error.

### `AssetGroupOperation` and `AssetGroupAssetOperation` requirements

When you create [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup.md.txt) resources with associated
[`Asset`](https://developers.google.com/google-ads/api/reference/rpc/v26/Asset.md.txt) resources using [`AssetGroupAsset`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupAsset.md.txt) to meet
the [minimum asset requirements](https://developers.google.com/google-ads/api/performance-max/asset-requirements.md.txt), the
[`MutateOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/MutateOperation.md.txt) objects that create the `AssetGroup` and
`AssetGroupAsset` resources in a batch job must be sequential without other
operations in between because of how these operations are grouped into
[atomic sub-batches](https://developers.google.com/google-ads/api/docs/batch-processing/best-practices.md.txt#atomicity-in-batch-splitting) (up to 1,000 operations
total per sub-batch). Specify the same negative [temporary ID](https://developers.google.com/google-ads/api/docs/batch-processing/temporary-ids.md.txt)
in the `AssetGroup` `create` operation (`resource_name`) and its consecutive
`AssetGroupAsset` `create` operations (`asset_group`), and place any
prerequisite [`AssetOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetOperation.md.txt) `create` operations **before**
the `AssetGroup` creation. Otherwise, the request fails with an
[`AssetGroupError` indicating some assets are
missing](https://developers.google.com/google-ads/api/performance-max/troubleshooting#common-asset-group-errors), even if the operations required to
[meet minimum asset requirements](https://developers.google.com/google-ads/api/performance-max/asset-requirements.md.txt) are included later in the
operations list.

### `AssetGroupListingGroupFilterOperation` best practices

> [!NOTE]
> **Note:** [`AssetGroupListingGroupFilter`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilter.md.txt) resources can only be used with Performance Max campaigns for [online sales with a product feed](https://developers.google.com/google-ads/api/performance-max/retail.md.txt). [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup.md.txt) resources in such campaigns must have a [valid product group tree](https://developers.google.com/google-ads/api/performance-max/listing-groups.md.txt) composed of one or more [`AssetGroupListingGroupFilter`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilter.md.txt) resources associated with it. To target all products, use a single node tree.

When you create, update, or remove
[`AssetGroupListingGroupFilter`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilter.md.txt) resources, add all
[`AssetGroupListingGroupFilterOperation`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroupListingGroupFilterOperation.md.txt) operations
targeting the same [`AssetGroup`](https://developers.google.com/google-ads/api/reference/rpc/v26/AssetGroup.md.txt) to the batch job consecutively
so that the operations are grouped into an atomic sub-batch during batch
splitting. For details on batch splitting and other factors affecting listing
groups, see the [listing group batch processing guide](https://developers.google.com/google-ads/api/docs/batch-processing/listing-groups.md.txt).

## Add the mutate operations to the job

Add the mutate operations from [Step 2](https://developers.google.com/google-ads/api/performance-max/batch-processing.md.txt#prepareoperations) to a list and call
the [`AddBatchJobOperations`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJobService/AddBatchJobOperations.md.txt) method to add the list
of mutations to the batch job created in [Step 1](https://developers.google.com/google-ads/api/performance-max/batch-processing.md.txt#createjob). Follow the
[add operations step](https://developers.google.com/google-ads/api/docs/batch-processing/flow.md.txt#addoperations) in the general batch processing guide
to add the list of mutate operations.

## Run the batch job

Start running the uploaded operations by calling the
[`RunBatchJob`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJobService/RunBatchJob.md.txt) method. See the [Run the batch job](https://developers.google.com/google-ads/api/docs/batch-processing/flow.md.txt#runjob)
step in the general batch processing guide for an example.

## Poll the job status and retrieve results

Batch jobs run as long-running operations and usually take time to finish. After
you start the job, use the [`Operations.GetOperation`](https://developers.google.com/google-ads/api/reference/rpc/google.longrunning.md.txt#google.longrunning.Operations.GetOperation) method
on the [`google.longrunning.Operations`](https://developers.google.com/google-ads/api/reference/rpc/google.longrunning.md.txt#google.longrunning.Operations) service (or query
[`batch_job.status`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJob.md.txt#status) with `GoogleAdsService`) to
[poll the job's status](https://developers.google.com/google-ads/api/docs/batch-processing/flow.md.txt#pollstatus) until it's done.

When the batch job finishes, call the
[`ListBatchJobResults`](https://developers.google.com/google-ads/api/reference/rpc/v26/BatchJobService/ListBatchJobResults.md.txt) method to retrieve the status
and response for each operation in the job. For an example, see
[List all batch job results](https://developers.google.com/google-ads/api/docs/batch-processing/flow.md.txt#listresults).