New API adding product to AdGroup

54 views
Skip to first unread message

David Courtney

unread,
Dec 11, 2017, 4:15:29 AM12/11/17
to AdWords API Forum
Hi,

I am having trouble adding a new product offer to an existing adgroup. I used to do it like this but can't seem to get the code working with the new API:


  $adGroupCriterionService = $user->GetService('AdGroupCriterionService', ADWORDS_VERSION);
  $helper
= new ProductPartitionHelper($adGroupId);
  $root
= $helper->createSubdivision();


 
if (is_array($ids)) { // Then there are options for the item and we need to add them all
   
foreach ($ids AS $ident) {
      $helper
->createUnit($root, new ProductOfferId($ident), 500000);
   
}
 
} else {
   
// Ad Product Partion
    $helper
->createUnit($root, new ProductOfferId($id), 500000);
 
}
  $helper
->createUnit($root,new ProductOfferId(null));
  $result
= $adGroupCriterionService->mutate($helper->getOperations());


I can't seem to find that specific example in the docs either.

Any help would be appreciated.

Thanks

Dave

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Dec 11, 2017, 2:39:19 PM12/11/17
to AdWords API Forum
Hi Dave, 

You can refer to the AddProductPartitionTree sample in PHP for code samples of adding a product partition tree. You will need to use the ProductOfferId as product dimension in this case. Also, please note that the tree must always remain complete, so any mutate operation that would make a tree invalid must be part of the same request as an operation that fixes it again. To be valid, all child nodes of a subdivision must have a caseValue of the same type, and every subdivision must contain an "other" node.

If you are facing any issues while trying this out, could you please enable logging and share the SOAP logs for this operation? Please use reply privately to author while sharing the logs.

Thanks,
Sreelakshmi, AdWords API Team

David Courtney

unread,
Dec 13, 2017, 9:53:53 AM12/13/17
to AdWords API Forum
I think I have figured it out with the following code for anyone who is interested!

$adGroupId = 'adgroupid';


$operations1
= [];


// This is creating the root partition
$root
= ProductPartitions::createSubdivision();
$criterion
= ProductPartitions::asBiddableAdGroupCriterion($adGroupId, $root);
$operation1
= ProductPartitions::createAddOperation($criterion);
$operations1
[] = $operation1;


// This is the product offer unit
$product
= new ProductOfferId();
$product
->setValue($productid);
$productUnit
= ProductPartitions::createUnit($root, $product);
$criterion
= ProductPartitions::asBiddableAdGroupCriterion($adGroupId, $productUnit, 500000);
$operation1
= ProductPartitions::createAddOperation($criterion);
$operations1
[] = $operation1;


// Then this is the OTHER part which needs to be added - in this case it is a all other products excluded
$otherProduct
= ProductPartitions::createUnit($root, new ProductOfferId());
$criterion
= ProductPartitions::asNegativeAdGroupCriterion($adGroupId, $otherProduct);
$operation1
= ProductPartitions::createAddOperation($criterion);
$operations1
[] = $operation1;


$adGroupCriterionService
= $adWordsServices->get($session, AdGroupCriterionService::class);


$result
= $adGroupCriterionService->mutate($operations1);


print_r
($result);

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Dec 13, 2017, 2:13:51 PM12/13/17
to AdWords API Forum
Hi David, 

Glad that you resolved the issue. Each product partition subdivision must contain a node representing "others". A node with "empty" caseValue of the correct type, will represent "all other values". Please check here for more details. 

David Courtney

unread,
Dec 14, 2017, 4:35:13 AM12/14/17
to AdWords API Forum
Yes, strangely though I had to add a negative node for the the empty "Other" node for it to work rather than a biddable empty node.

Thanks for your help.


On Monday, December 11, 2017 at 9:15:29 AM UTC, David Courtney wrote:

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Dec 14, 2017, 3:47:33 PM12/14/17
to AdWords API Forum
Hi David, 

You should be able to add the others node as a biddable criterion. Please see the attached SOAP request from my testing. What error where you getting while trying to add that as a biddable criterion? 
SOAP_LOG_ProductPartition
Reply all
Reply to author
Forward
0 new messages