Stay organized with collectionsSave and categorize content based on your preferences.
Now that we've seen how to create mutate operations for the individual entities
required to create a new Smart campaign, we can combine them into a single
request that creates them all at once.
The benefits of using a single mutate request are:
Reduces complexity since these entities are not shared and highly dependent
on each other.
Prevents orphaned entities from existing if one of the operations fails for
any reason.
When using temporary resource names to create entities in a single request like
this, ensure that you order the operations such that entities with dependencies
are created first.
# The below methods create and return MutateOperations that we later# provide to the GoogleAdsService.Mutate method in order to create the# entities in a single request. Since the entities for a Smart campaign# are closely tied to one-another it's considered a best practice to# create them in a single Mutate request so they all complete successfully# or fail entirely, leaving no orphaned entities. See:# https://developers.google.com/google-ads/api/docs/mutating/overviewcampaign_budget_operation:MutateOperation=(create_campaign_budget_operation(client,customer_id,suggested_budget_amount))smart_campaign_operation:MutateOperation=create_smart_campaign_operation(client,customer_id)smart_campaign_setting_operation:MutateOperation=(create_smart_campaign_setting_operation(client,customer_id,business_profile_location,business_name))campaign_criterion_operations:List[MutateOperation]=(create_campaign_criterion_operations(client,customer_id,keyword_theme_infos,suggestion_info))ad_group_operation:MutateOperation=create_ad_group_operation(client,customer_id)ad_group_ad_operation:MutateOperation=create_ad_group_ad_operation(client,customer_id,ad_suggestions)googleads_service:GoogleAdsServiceClient=client.get_service("GoogleAdsService")# Send the operations into a single Mutate request.response:MutateGoogleAdsResponse=googleads_service.mutate(customer_id=customer_id,mutate_operations=[# It's important to create these entities in this order because# they depend on each other, for example the SmartCampaignSetting# and ad group depend on the campaign, and the ad group ad depends# on the ad group.campaign_budget_operation,smart_campaign_operation,smart_campaign_setting_operation,# Expand the list of campaign criterion operations into the list of# other mutate operations*campaign_criterion_operations,ad_group_operation,ad_group_ad_operation,],)print_response_details(response)
# The below methods create and return MutateOperations that we later# provide to the GoogleAdsService.Mutate method in order to create the# entities in a single request. Since the entities for a Smart campaign# are closely tied to one-another it's considered a best practice to# create them in a single Mutate request so they all complete successfully# or fail entirely, leaving no orphaned entities. See:# https://developers.google.com/google-ads/api/docs/mutating/overviewmutate_operations=[]# It's important to create these operations in this order because# they depend on each other, for example the SmartCampaignSetting# and ad group depend on the campaign, and the ad group ad depends# on the ad group.mutate_operations<<create_campaign_budget_operation(client,customer_id,suggested_budget_amount,)mutate_operations<<create_smart_campaign_operation(client,customer_id,)mutate_operations<<create_smart_campaign_setting_operation(client,customer_id,business_profile_location,business_name,)mutate_operations+=create_campaign_criterion_operations(client,customer_id,keyword_theme_infos,suggestion_info,)mutate_operations<<create_ad_group_operation(client,customer_id)mutate_operations<<create_ad_group_ad_operation(client,customer_id,ad_suggestions)# Sends the operations into a single Mutate request.response=client.service.google_ads.mutate(customer_id:customer_id,mutate_operations:mutate_operations,)print_response_details(response)
# The below methods create and return MutateOperations that we later provide to the# GoogleAdsService.Mutate method in order to create the entities in a single# request. Since the entities for a Smart campaign are closely tied to one-another# it's considered a best practice to create them in a single Mutate request; the# entities will either all complete successfully or fail entirely, leaving no# orphaned entities. See:# https://developers.google.com/google-ads/api/docs/mutating/overviewmy$campaign_budget_operation=_create_campaign_budget_operation($customer_id,$suggested_budget_amount);my$smart_campaign_operation=_create_smart_campaign_operation($customer_id);my$smart_campaign_setting_operation=_create_smart_campaign_setting_operation($customer_id,$business_profile_location,$business_name);my$campaign_criterion_operations=_create_campaign_criterion_operations($customer_id,$keyword_theme_infos,$suggestion_info);my$ad_group_operation=_create_ad_group_operation($customer_id);my$ad_group_ad_operation=_create_ad_group_ad_operation($customer_id,$ad_suggestions);# It's important to create these entities in this order because they depend on# each other. For example, the SmartCampaignSetting and ad group depend on the# campaign and the ad group ad depends on the ad group.my$mutate_operations=[$campaign_budget_operation,$smart_campaign_operation,$smart_campaign_setting_operation,# Expand the list of campaign criterion operations into the list of# other mutate operations.@$campaign_criterion_operations,$ad_group_operation,$ad_group_ad_operation];# Send the operations in a single mutate request.my$mutate_google_ads_response=$api_client->GoogleAdsService()->mutate({customerId=>$customer_id,mutateOperations=>$mutate_operations});_print_response_details($mutate_google_ads_response);
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Missing the information I need","missingTheInformationINeed","thumb-down"],["Too complicated / too many steps","tooComplicatedTooManySteps","thumb-down"],["Out of date","outOfDate","thumb-down"],["Samples / code issue","samplesCodeIssue","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-09-03 UTC."],[[["\u003cp\u003eCreating Smart campaign entities in a single mutate request reduces complexity and prevents orphaned entities.\u003c/p\u003e\n"],["\u003cp\u003eUsing temporary resource names in a single request requires ordering operations to ensure entities with dependencies are created first.\u003c/p\u003e\n"],["\u003cp\u003eThe provided code examples demonstrate how to send a single mutate request containing multiple operations for creating a new Smart campaign.\u003c/p\u003e\n"]]],[],null,[]]