Unable to change keyword bids PHP v201710

30 views
Skip to first unread message

Josh Averbeck

unread,
Dec 21, 2017, 1:19:47 AM12/21/17
to AdWords API Forum
Hello,

I am trying to do something extremely simple: change keyword bids. I think my code is correct but I'm probably wrong. I've searched the documentation for over four hours and can't find anything to help me. Unfortunately all other languages have examples of changing bids, the PHP example focuses on changing keyword final URLs. All of the other examples in the forum are using outdated versions of the PHP library. Anyway, the code:

$adGroupCriterion = new BiddableAdGroupCriterion();
$adGroupCriterion->setAdGroupId($adGroupId);
$adGroupCriterion->setCriterion(new Criterion([KEYWORD_ID]));
$biddingStrategyConfiguration = new BiddingStrategyConfiguration();

$money = new Money;
$money->setMicroAmount(500000);
$bid = new CpcBid;
$bid->setBid($money);
$biddingStrategyConfiguration->setBids(new Bid([$bid]));

$operation = new AdGroupCriterionOperation();
$operation->setOperand($adGroupCriterion);
$operation->setOperator(Operator::SET);
$operations[] = $operation;
$result = $adGroupCriterionService->mutate($operations);
$adGroupCriterion = $result->getValue()[0];

Now the problem is that $biddingStrategyConfiguration->setBids(new Bid([$bid])); always returns an error because it requires an array but $bid->setBid($money); returns an object thus causing error. Am I doing something wrong here? Please help.

Vincent Racaza (AdWords API Team)

unread,
Dec 21, 2017, 2:53:46 AM12/21/17
to AdWords API Forum
Hi Josh,

Checking your code, I have observed that you missed some code lines, that's why, it generated an error on your end. You may refer to the changes that I made in your code below:

$adGroupCriterion = new BiddableAdGroupCriterion();
$adGroupCriterion
->setAdGroupId($adGroupId);

$adGroupCriterion
->setCriterion(new Criterion(KEYWORD_ID));
$biddingStrategyConfiguration = new BiddingStrategyConfiguration();

$money 
= new Money;
$money
->setMicroAmount(500000);
$bid 
= new CpcBid;
$bid
->setBid($money);

$biddingStrategyConfiguration
->setBids([$bid]);
$adGroupCriterion
->setBiddingStrategyConfiguration($biddingStrategyConfiguration);


$operation 
= new AdGroupCriterionOperation();
$operation
->setOperand($adGroupCriterion);
$operation
->setOperator(Operator::SET);
$operations
[] = $operation;
$result 
= $adGroupCriterionService->mutate($operations);
$adGroupCriterion 
= $result->getValue()[0];

Hope this helps. If the issue persists, please provide your SOAP request and response logs via Reply privately to author option.

Thanks,
Vincent
AdWords API Team 
Reply all
Reply to author
Forward
0 new messages