budget issue in creation new campaign.

60 views
Skip to first unread message

Oleg Disrupt

unread,
Nov 15, 2021, 2:18:19 AM11/15/21
to AdWords API and Google Ads API Forum
Hello
when i try to run this script,  I can see new budget(shared budget) with new campaign.
php examples/BasicOperations/AddCampaigns.php --customerId 9641267633
I only want to create new campaign with individual campaign budget (only budget number) not user addCampaignBudget
for example
$campaign = new Campaign([
                'name' => 'campaign1',
                ....
                'campaign_budget' => 10,
                ...
            ]);

How can i do that?
Thanks

Google Ads API Forum Advisor

unread,
Nov 15, 2021, 3:11:37 AM11/15/21
to ol...@disrupt.social, adwor...@googlegroups.com
Hi Oleg,

Thank you for posting your concern.

You may try to remove the implementation for creating a budget, then you may insert a report for campaign_budget to get the resource name of the campaign budget. After retrieving the resource name, then set it to the campaign_budget field of the Campaign resource.

Let me know if you have questions with the provided suggestion.

Regards,

Reminder: Share your feedback about the Google Ads (AdWords) API! Take the 2021 Google Ads API and AdWords API Annual Survey
 
Google Logo
Ernie John Blanca Tacata
Google Ads API Team
 


ref:_00D1U1174p._5004Q2R92yB:ref

jindong o

unread,
Nov 15, 2021, 3:13:41 AM11/15/21
to AdWords API and Google Ads API Forum
you should use budget resource.
and you can check Campaign resource class.
It is important to look at the class definition and variable types and names while using the google ads api.
this is my past working code snippet. 
$budgetResourceName = self::addCampaignBudget($googleAdsClient, $cam_infos['customer_id'], $cam_infos['campaign_budget']);
.....
$campaign = new Campaign([
                'name' => $cam_infos['campaign_name'],
                'advertising_channel_type' => $cam_infos['advertising_channel_type'],              
                'status' => $cam_infos['status'],
                'manual_cpc' => new ManualCpc(['enhanced_cpc_enabled'=>true]),
                'bidding_strategy_type'=>$cam_infos['bidding_strategy_type'],
                'tracking_url_template'=>$cam_infos['tracking_template'],
                'campaign_budget' => $budgetResourceName,
                'network_settings' => $networkSettings,
                'start_date' => $cam_infos['start_date'],
                //'end_date' => $cam_infos['end_date']
            ]);
......
private static function addCampaignBudget(GoogleAdsClient $googleAdsClient, int $customerId,int $campaign_budget){
        // Creates a campaign budget.
        $budget = new CampaignBudget([
            'name' => 'non shared budget#' . Helper::getPrintableDatetime(),
            'delivery_method' => BudgetDeliveryMethod::STANDARD,
            'amount_micros' => $campaign_budget,
            'explicitly_shared' => false // this is for non-shared budget
        ]);

        // Creates a campaign budget operation.
        $campaignBudgetOperation = new CampaignBudgetOperation();
        $campaignBudgetOperation->setCreate($budget);

        // Issues a mutate request.
        $campaignBudgetServiceClient = $googleAdsClient->getCampaignBudgetServiceClient();
        $response = $campaignBudgetServiceClient->mutateCampaignBudgets(
            $customerId,
            [$campaignBudgetOperation]
        );

        /** @var CampaignBudget $addedBudget */
        $addedBudget = $response->getResults()[0];
        //printf("Added budget named '%s'%s", $addedBudget->getResourceName(), PHP_EOL);

        return $addedBudget->getResourceName();

jindong o

unread,
Nov 15, 2021, 3:27:51 AM11/15/21
to AdWords API and Google Ads API Forum
Yes, Sample code use shared budget.
you can use non-shared budget like this...
$budget = new CampaignBudget([
            'name' => 'non shared budget#' . Helper::getPrintableDatetime(),
            'delivery_method' => BudgetDeliveryMethod::STANDARD,
            'amount_micros' => $campaign_budget,
            'explicitly_shared' => false
        ]);


Google Ads API Forum Advisor

unread,
Nov 15, 2021, 4:17:51 AM11/15/21
to ol...@disrupt.social, adwor...@googlegroups.com
Hi everyone,

Thank you Jindong for your input regarding the explicitly_shared attribute.

@Oleg, you can also check here, for more information on how to set a campaign budget only for a single campaign. If you continue to encounter issues, you may provide our team with the complete request and response logs, along with the request-id.

You may then send the requested information via the Reply privately to author option. If this option is not available, you may send the details directly to our googleadsa...@google.com alias instead.

Best regards,


Reminder: Share your feedback about the Google Ads (AdWords) API! Take the 2021 Google Ads API and AdWords API Annual Survey
 
Google Logo
Peter Laurence Napa Oliquino
Google Ads API Team
 


ref:_00D1U1174p._5004Q2R92yB:ref
Reply all
Reply to author
Forward
0 new messages