Stay organized with collectionsSave and categorize content based on your preferences.
The following example shows how to build aMutateOperationthat creates a newCampaignBudgetfor a Smart campaign. This
operation will be used in a single mutate request along with the other entities
required to create a Smart campaign.
Key requirements for Smart campaign budgets:
A Smart campaign budget cannot be shared with more than one campaign.
defcreate_campaign_budget_operation(client:GoogleAdsClient,customer_id:str,suggested_budget_amount:int)->MutateOperation:"""Creates a MutateOperation that creates a new CampaignBudget.A temporary ID will be assigned to this campaign budget so that it can bereferenced by other objects being created in the same Mutate request.Args:client: an initialized GoogleAdsClient instance.customer_id: a client customer ID.suggested_budget_amount: a numeric daily budget amount in micros.Returns:a MutateOperation that creates a CampaignBudget."""mutate_operation:MutateOperation=client.get_type("MutateOperation")campaign_budget_operation:CampaignBudgetOperation=(mutate_operation.campaign_budget_operation)campaign_budget:CampaignBudget=campaign_budget_operation.createcampaign_budget.name=f"Smart campaign budget #{uuid4()}"# A budget used for Smart campaigns must have the type SMART_CAMPAIGN.# Note that the field name "type_" is an implementation detail in Python,# the field's actual name is "type".campaign_budget.type_=client.enums.BudgetTypeEnum.SMART_CAMPAIGN# The suggested budget amount from the SmartCampaignSuggestService is# a daily budget. We don't need to specify that here, because the budget# period already defaults to DAILY.campaign_budget.amount_micros=suggested_budget_amount# Set a temporary ID in the budget's resource name so it can be referenced# by the campaign in later steps.campaign_budget.resource_name=client.get_service("CampaignBudgetService").campaign_budget_path(customer_id,_BUDGET_TEMPORARY_ID)returnmutate_operation
# Creates a mutate_operation that creates a new campaign_budget.# A temporary ID will be assigned to this campaign budget so that it can be# referenced by other objects being created in the same mutate request.defcreate_campaign_budget_operation(client,customer_id,suggested_budget_amount)mutate_operation=client.operation.mutatedo|m|m.campaign_budget_operation=client.operation.create_resource.campaign_budgetdo|cb|cb.name="Smart campaign budget ##{(Time.new.to_f*1000).to_i}"# A budget used for Smart campaigns must have the type SMART_CAMPAIGN.cb.type=:SMART_CAMPAIGN# The suggested budget amount from the smart_campaign_suggest_service is# a daily budget. We don't need to specify that here, because the budget# period already defaults to DAILY.cb.amount_micros=suggested_budget_amount# Sets a temporary ID in the budget's resource name so it can be referenced# by the campaign in later steps.cb.resource_name=client.path.campaign_budget(customer_id,BUDGET_TEMPORARY_ID)endendmutate_operationend
# Creates a MutateOperation that creates a new CampaignBudget.# A temporary ID will be assigned to this campaign budget so that it can be# referenced by other objects being created in the same Mutate request.sub_create_campaign_budget_operation{my($customer_id,$suggested_budget_amount)=@_;returnGoogle::Ads::GoogleAds::V21::Services::GoogleAdsService::MutateOperation->new({campaignBudgetOperation=>Google::Ads::GoogleAds::V21::Services::CampaignBudgetService::CampaignBudgetOperation->new({create=>Google::Ads::GoogleAds::V21::Resources::CampaignBudget->new({name=>"Smart campaign budget #".uniqid(),# A budget used for Smart campaigns must have the type SMART_CAMPAIGN.type=>Google::Ads::GoogleAds::V21::Enums::BudgetTypeEnum::SMART_CAMPAIGN,# The suggested budget amount from the SmartCampaignSuggestService is# a daily budget. We don't need to specify that here, because the# budget period already defaults to DAILY.amountMicros=>$suggested_budget_amount,# Set a temporary ID in the budget's resource name so it can be# referenced by the campaign in later steps.resourceName=>Google::Ads::GoogleAds::V21::Utils::ResourceNames::campaign_budget($customer_id,BUDGET_TEMPORARY_ID)})})});}
[[["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\u003eThis guide provides code samples in various languages demonstrating how to build a \u003ccode\u003eMutateOperation\u003c/code\u003e that creates a new \u003ccode\u003eCampaignBudget\u003c/code\u003e for Smart campaigns within Google Ads.\u003c/p\u003e\n"],["\u003cp\u003eIt highlights the requirement of using the \u003ccode\u003eSMART_CAMPAIGN\u003c/code\u003e budget type and suggests using the budget amount retrieved from \u003ccode\u003eSmartCampaignSuggestService\u003c/code\u003e.\u003c/p\u003e\n"],["\u003cp\u003eThe provided examples show how to set a temporary ID for the budget to allow referencing by other campaign entities in the same request.\u003c/p\u003e\n"],["\u003cp\u003eSmart campaign budgets cannot be shared across multiple campaigns and automatically default to a daily budget period.\u003c/p\u003e\n"]]],[],null,[]]