$budgetResourceName = $this->addCampaignBudget(10000.36);
// Creates a campaign.
$campaign = new Campaign([
'name' => 'THIL_DISPLAY',
'advertising_channel_type' => AdvertisingChannelType::DISPLAY,
'status' => CampaignStatus::PAUSED,
'campaign_budget' => $budgetResourceName,
// Sets the standard bidding strategy and budget.
'target_spend' => new TargetSpend(
['cpc_bid_ceiling_micros' => $camp_data['budget'] * 1000000]
),
// Optional: Sets the start and end dates.
'start_date' => date('Ymd', strtotime($camp_data['start_date'])),
'end_date' => date('Ymd', strtotime($camp_data['end_date']))
]);
// Creates a campaign operation.
$campaignOperation = new CampaignOperation();
$campaignOperation->setCreate($campaign);
$campaignServiceClient = $this->googleAdsClient->getCampaignServiceClient();
$campaignResponse = $campaignServiceClient->mutateCampaigns($this->CUSTOMER_ID, [$campaignOperation]);
$campaignResourceName = $campaignResponse->getResults()[0]->getResourceName();
return $campaignResourceName;
public function addCampaignBudget($budget) {
$budget = new CampaignBudget([
'name' => 'Budget #'.$budget_name,
'delivery_method' => BudgetDeliveryMethod::STANDARD,
// 'amount_micros' => $budget * 1000000, //*1000000
'total_amount_micros' => 1000000, //*1000000
'period' => BudgetPeriod::CUSTOM_PERIOD,
'explicitly_shared' => false
]);
$campaignBudgetOperation = new CampaignBudgetOperation();
$campaignBudgetOperation->setCreate($budget);
$campaignBudgetServiceClient = $this->googleAdsClient->getCampaignBudgetServiceClient();
$response = $campaignBudgetServiceClient->mutateCampaignBudgets(
$this->CUSTOMER_ID,
[$campaignBudgetOperation]
);
$addedBudget = $response->getResults()[0];
return $addedBudget->getResourceName();
}
When i set amount_micros (without total_amount_micros & period) then the campaign budget is setting up as daily budget.
So i set total_amount_micros & period then i'm getting error like OPERATION_NOT_PERMITTED_FOR_CAMPAIGN_TYPE.
Also i tried to set amount_micros & period then im getting error like below :
{
"message": "Request contains an invalid argument.",
"code": 3,
"status": "INVALID_ARGUMENT",
"details": [
{
"@type": 0,
"data": "type.googleapis.com\/google.ads.googleads.v8.errors.GoogleAdsFailure"
},
{
"@type": 0,
"data": [
{
"errorCode": {
"requestError": "UNKNOWN"
},
"message": "The error code is not in this version.",
"trigger": {
"int64Value": "10000360000"
},
"location": {
"fieldPathElements": [
{
"fieldName": "operations",
"index": 0
},
{
"fieldName": "create"
},
{
"fieldName": "amount_micros"
}
]
}
}
]
},
{
"@type": 0,
"data": "wxH3aLWrIaZcf1gOHCyx4w"
}
]
}