Create a budget

  • A MutateOperation is used to create a new CampaignBudget for a Smart campaign, which will be part of a single mutate request.

  • It is recommended to use the budget amount in micros retrieved from the SmartCampaignSuggestService when creating the budget.

  • Smart campaign budgets cannot be shared and must have their type set to BudgetTypeEnum.SMART_CAMPAIGN.

The following example shows how to build a MutateOperation that creates a new CampaignBudget for 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:

Java

private MutateOperation createCampaignBudgetOperation(long customerId, long dailyBudgetMicros) {
  MutateOperation.Builder builder = MutateOperation.newBuilder();
  builder
      .getCampaignBudgetOperationBuilder()
      .getCreateBuilder()
      .setName("Smart campaign budget " + CodeSampleHelper.getShortPrintableDateTime())
      .setDeliveryMethod(BudgetDeliveryMethod.STANDARD)
      // A budget used for Smart campaigns must have the type SMART_CAMPAIGN.
      .setType(BudgetType.SMART_CAMPAIGN)
      // The suggested budget amount from the SmartCampaignSuggestService is for a _daily_ budget.
      // We don't need to specify that here, because the budget period already defaults to DAILY.
      .setAmountMicros(dailyBudgetMicros)
      // Sets a temporary ID in the budget's resource name so it can be referenced by the campaign
      // in later steps.
      .setResourceName(ResourceNames.campaignBudget(customerId, BUDGET_TEMPORARY_ID));
  return builder.build();
}
      

C#

/// <summary>
/// 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.
/// </summary>
/// <param name="customerId">The Google Ads customer ID.</param>
/// <param name="suggestedBudgetAmount">A daily amount budget in micros.</param>
/// <returns>A MutateOperation that creates a CampaignBudget</returns>
private MutateOperation CreateCampaignBudgetOperation(long customerId,
    long suggestedBudgetAmount)
{
    return new MutateOperation
    {
        CampaignBudgetOperation = new CampaignBudgetOperation
        {
            Create = new CampaignBudget
            {
                Name = $"Smart campaign budget #{ExampleUtilities.GetRandomString()}",
                // A budget used for Smart campaigns must have the type SMART_CAMPAIGN.
                Type = BudgetType.SmartCampaign,
                // 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 = suggestedBudgetAmount,
                // Set a temporary ID in the budget's resource name so it can be referenced
                // by the campaign in later steps.
                ResourceName = ResourceNames.CampaignBudget(
                    customerId, BUDGET_TEMPORARY_ID)
            }
        }
    };
}
      

PHP

private static function createCampaignBudgetOperation(
    int $customerId,
    int $suggestedBudgetAmount
): MutateOperation {
    // Creates the campaign budget object.
    $campaignBudget = new CampaignBudget([
        'name' => "Smart campaign budget #" . Helper::getPrintableDatetime(),
        // A budget used for Smart campaigns must have the type SMART_CAMPAIGN.
        'type' => BudgetType::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.
        'amount_micros' => $suggestedBudgetAmount,
        // Sets a temporary ID in the budget's resource name so it can be referenced by the
        // campaign in later steps.
        'resource_name' =>
            ResourceNames::forCampaignBudget($customerId, self::BUDGET_TEMPORARY_ID)
    ]);

    // Creates the MutateOperation that creates the campaign budget.
    return new MutateOperation([
        'campaign_budget_operation' => new CampaignBudgetOperation([
            'create' => $campaignBudget
        ])
    ]);
}