Page Summary
-
Partial failure is a Google Ads API feature allowing valid operations to be committed while failed ones return errors, which can then be handled separately.
-
Not all Google Ads API services and methods support partial failure; check for the
partial_failurefield in the request to confirm support. -
To use partial failure, set the
partialFailureparameter in the method request. -
Requests with interdependent operations that require cross-operation resource referencing using temporary IDs are not suitable for partial failure.
-
You can identify failed operations in the response by checking for empty results and detailed errors within the
partial_failure_errorfield.
In the Google Ads API, you can request that valid operations be committed and failed ones return errors. This feature—called partial failure—lets you handle the failed operations separately at the end. It is available in non-get methods of many Google Ads API services.
Technical details
To utilize this feature, set the partialFailure parameter of the method you'd
like to use. This can be a bit different in each client library. For example, do
the following to turn on this feature when sending a request using
MutateAdGroups:
Java
mutateAdGroups(String.valueOf(customerId), operations, true)
C#
MutateAdGroups(customerId.ToString(), operations, true, false)
PHP
mutateAdGroups($customerId, $operations, ['partialFailure' => true])Python
mutate_ad_groups(customer_id, operations, partial_failure=True)
Ruby
mutate_ad_groups(customer_id, operations, partial_failure: true)
Perl
mutate({customerId => $customer_id, operations => $operations, partialFailure => 'true'})
The service will carry out the operations that had no errors. It will return results for successful operations and errors for failed ones.
Usage
Suppose you need to add a set of ad groups to your account, but some of the ad groups may have some issues. You want to create the valid ad groups, but have the failed ad groups returned along with their errors.
When to avoid partial failure
You shouldn't use partial failure for requests with interdependent operations.
For example, if you are creating a complex entity that requires multiple
resources to be created in a single request, such as a Performance Max campaign,
you shouldn't use partial failure. The initial creation of a Performance Max
campaign requires creating Campaign and
CampaignAsset resources in the same request. If
the Campaign creation fails, the
CampaignAsset creation will also fail, and you
should treat the request as a single atomic failure.
As another example, don't use partial failure when you first add required
assets to an AssetGroup. Asset groups can be
created with no assets, or with all required assets. When first adding assets to
the asset group, you can't add them one at a time in separate requests. You must
include them all in one request, and you shouldn't use partial failure. After
the asset group has all the required assets, you can add or remove assets one at
a time, and those requests can use partial failure.
To determine if partial failure is appropriate, check if a temporary ID is needed for cross-operation resource referencing within the same request. If so, you shouldn't use partial failure, because the success of the second operation is dependent on the success of the first.
Create the operations and make the API call
Create the mutate operations and make the API call as usual.
Java
private MutateAdGroupsResponse createAdGroups( GoogleAdsClient googleAdsClient, long customerId, long campaignId) { // This AdGroup should be created successfully - assuming the campaign in the params exists. AdGroup group1 = AdGroup.newBuilder() .setCampaign(ResourceNames.campaign(customerId, campaignId)) .setName("Valid AdGroup: " + getPrintableDateTime()) .build(); // This AdGroup will always fail - campaign ID 0 in resource names is never valid. AdGroup group2 = AdGroup.newBuilder() .setCampaign(ResourceNames.campaign(customerId, 0L)) .setName("Broken AdGroup: " + getPrintableDateTime()) .build(); // This AdGroup will always fail - duplicate ad group names are not allowed. AdGroup group3 = AdGroup.newBuilder() .setCampaign(ResourceNames.campaign(customerId, campaignId)) .setName(group1.getName()) .build(); AdGroupOperation op1 = AdGroupOperation.newBuilder().setCreate(group1).build(); AdGroupOperation op2 = AdGroupOperation.newBuilder().setCreate(group2).build(); AdGroupOperation op3 = AdGroupOperation.newBuilder().setCreate(group3).build(); try (AdGroupServiceClient service = googleAdsClient.getLatestVersion().createAdGroupServiceClient()) { // Issues the mutate request, setting partialFailure=true. return service.mutateAdGroups( MutateAdGroupsRequest.newBuilder() .setCustomerId(String.valueOf(customerId)) .setCustomerId(Long.toString(customerId)) .addAllOperations(Arrays.asList(op1, op2, op3)) .setPartialFailure(true) .build()); } }
C#
private static MutateAdGroupsResponse CreateAdGroups(GoogleAdsClient client, long customerId, long campaignId) { // Get the AdGroupServiceClient. AdGroupServiceClient adGroupService = client.GetService(Services.V22.AdGroupService); string validAdGroupName = "Valid AdGroup: " + ExampleUtilities.GetRandomString(); AdGroupOperation[] operations = new AdGroupOperation[] { // This operation will be successful, assuming the campaign specified in // campaignId parameter is correct. new AdGroupOperation() { Create = new AdGroup() { Campaign = ResourceNames.Campaign(customerId, campaignId), Name = validAdGroupName } }, // This operation will fail since we are using campaign ID = 0, which results // in an invalid resource name. new AdGroupOperation() { Create = new AdGroup() { Campaign = ResourceNames.Campaign(customerId, 0), Name = "Broken AdGroup: " + ExampleUtilities.GetRandomString() }, }, // This operation will fail since the ad group is using the same name as the ad // group from the first operation. Duplicate ad group names are not allowed. new AdGroupOperation() { Create = new AdGroup() { Campaign = ResourceNames.Campaign(customerId, campaignId), Name = validAdGroupName } } }; // Add the ad groups. MutateAdGroupsResponse response = adGroupService.MutateAdGroups(new MutateAdGroupsRequest() { CustomerId = customerId.ToString(), Operations = { operations }, PartialFailure = true, ValidateOnly = false }); return response; }
PHP
private static function createAdGroups( GoogleAdsClient $googleAdsClient, int $customerId, int $campaignId ) { $campaignResourceName = ResourceNames::forCampaign($customerId, $campaignId); // This ad group should be created successfully - assuming the campaign in the params // exists. $adGroup1 = new AdGroup([ 'name' => 'Valid AdGroup #' . Helper::getPrintableDatetime(), 'campaign' => $campaignResourceName ]); // This ad group will always fail - campaign ID 0 in the resource name is never valid. $adGroup2 = new AdGroup([ 'name' => 'Broken AdGroup #' . Helper::getPrintableDatetime(), 'campaign' => ResourceNames::forCampaign($customerId, 0) ]); // This ad group will always fail - duplicate ad group names are not allowed. $adGroup3 = new AdGroup([ 'name' => $adGroup1->getName(), 'campaign' => $campaignResourceName ]); $operations = []; $adGroupOperation1 = new AdGroupOperation(); $adGroupOperation1->setCreate($adGroup1); $operations[] = $adGroupOperation1; $adGroupOperation2 = new AdGroupOperation(); $adGroupOperation2->setCreate($adGroup2); $operations[] = $adGroupOperation2; $adGroupOperation3 = new AdGroupOperation(); $adGroupOperation3->setCreate($adGroup3); $operations[] = $adGroupOperation3; // Issues the mutate request, enabling partial failure mode. $adGroupServiceClient = $googleAdsClient->getAdGroupServiceClient(); return $adGroupServiceClient->mutateAdGroups( MutateAdGroupsRequest::build($customerId, $operations)->setPartialFailure(true) ); }