How To Select Existing Product Partitions

66 views
Skip to first unread message

ry...@n-i-e.co.uk

unread,
Mar 1, 2019, 2:34:41 PM3/1/19
to AdWords API and Google Ads API Forum
Hi, 

I am currently trying to update our Shopping campaign through the Google Ad's API and so far so good. 

I have a bit of an issue when hitting over 5000 requests. I am aware that there is a 5000 limit per request and I'm not too far off we have 5,600ish products in the shopping that I want on the Ad Campaign. 


Problem is I create the Ad Group and Partitions at the top of my script with this code: 

                       
                        $operations = [];
$root = ProductPartitions::createSubdivision(); ///This is what I think is causing the problem,
$criterion = ProductPartitions::asBiddableAdGroupCriterion($adGroupId, $root);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$otherCondition = ProductPartitions::createSubdivision(
$root,
new ProductCanonicalCondition()
);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$otherCondition
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
  
$otherBrand = ProductPartitions::createSubdivision(
$otherCondition,
new ProductOfferId()
);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$otherBrand
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
$productBiddingCategory = new ProductBiddingCategory();
$productBiddingCategory->setType(ProductDimensionType::BIDDING_CATEGORY_L1);
$productBiddingCategoryUnit = ProductPartitions::createUnit($otherBrand, $productBiddingCategory);
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$productBiddingCategoryUnit,
10000
);
$operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;



After I send the first 5000 operations I try to do another loop to send another 1400ish, the problem is where I run this code


                        $cheapBrand = new ProductOfferId(); 
$cheapBrand->setValue($sku); 
$cheapBrandUnit = ProductPartitions::createUnit($root, $cheapBrand); ///Where this line says $root I think it's trying to re-create $root rather than get the previously created.
$criterion = ProductPartitions::asBiddableAdGroupCriterion(
$adGroupId,
$cheapBrandUnit,
        $bid_trans
);
        $operation = ProductPartitions::createAddOperation($criterion);
$operations[] = $operation;
 

It seems because I don't store the $root object the code tries to re-create and then fails with error: 


 AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[1].operand.criterion.parentCriterionId; 
 

I can't delete and rebuild the Root partition as I just want to add to the existing 5000 request so in total there are 2 requests to build the partitions. 



googleadsapi...@google.com

unread,
Mar 1, 2019, 5:03:29 PM3/1/19
to AdWords API and Google Ads API Forum
Hi Ryan, 

You are right. To avoid this error, you could get the criterionId corresponding to the root and use that as the parentCriterionId in the next set of operations. A sample SOAP request is shown below: 

            <operations>
                <operator>ADD</operator>
                <operand xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201809" xsi:type="ns2:BiddableAdGroupCriterion">
                    <ns2:adGroupId>*****</ns2:adGroupId>
                    <ns2:criterion xsi:type="ns2:ProductPartition">
                        <ns2:id>-1</ns2:id>
                        <ns2:partitionType>UNIT</ns2:partitionType>
                        <ns2:parentCriterionId>293946777986</ns2:parentCriterionId>
                        <ns2:caseValue xsi:type="ns2:ProductCanonicalCondition">
                            <ns2:condition>REFURBISHED</ns2:condition>
                        </ns2:caseValue>
                    </ns2:criterion>
                    <ns2:biddingStrategyConfiguration>
                        <ns2:bids xsi:type="ns2:CpcBid">
                            <ns2:bid>
                                <ns2:microAmount>500000</ns2:microAmount>
                            </ns2:bid>
                            <ns2:cpcBidSource>CRITERION</ns2:cpcBidSource>
                        </ns2:bids>
                    </ns2:biddingStrategyConfiguration>
                    <ns2:urlCustomParameters>
                        <ns2:doReplace>true</ns2:doReplace>
                    </ns2:urlCustomParameters>
                </operand>
            </operations>
        </mutate>

Here is the code snippet for reference : 
...
use Google\AdsApi\AdWords\v201806\cm\ProductPartition;
use Google\AdsApi\AdWords\v201806\cm\ProductPartitionType;
...
        $operations = [];

        $root = new ProductPartition();
        $root->setPartitionType(ProductPartitionType::SUBDIVISION);
        $root->setId(293946777986);

        $refurbishedCondition = new ProductCanonicalCondition();
        $refurbishedCondition->setCondition(ProductCanonicalConditionCondition::REFURBISHED);
        $refurbishedConditionUnit = ProductPartitions::createUnit($root, $refurbishedCondition);
        $criterion = ProductPartitions::asBiddableAdGroupCriterion(
            $adGroupId,
            $refurbishedConditionUnit,
            600000
        );
        $operation = ProductPartitions::createAddOperation($criterion);
        $operations[] = $operation;

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


Could you give this a try and let me know if that fixes the issue?

Thanks,
Sreelakshmi, AdWords API Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

ry...@n-i-e.co.uk

unread,
Mar 4, 2019, 6:18:32 AM3/4/19
to AdWords API and Google Ads API Forum
thanks for the support, I tried your solution of setting the ID but I was getting issues because of new ProductPartition(); I was creating the partition using $root = ProductPartitions::createSubdivision(); so having use Google\AdsApi\AdWords\v201806\cm\ProductPartition; caused conflicts. 

I got around this by reading the response e.g $all_ids = ProductPartitions::showAdGroupTree($adWordsServices,$session,$adGroupId);

I then did explode to get the ID of the partition I needed. 

I had another issue as ProductPartitions::createUnit only allows for an object to be passed not a partition ID so I created an almost identical function which could read the ID not Object.

I now have 2 functions in my API code (ProductPartitions.php) for Creating Units. 

   
    public static function
createUnit(
        ProductPartition $parent = null,
        ProductDimension $value = null
    ) {
        $unit = new ProductPartition();
        $unit->setPartitionType(ProductPartitionType::UNIT);

        // The root node has neither a parent nor a value
        if ($parent !== null) {
            $unit->setParentCriterionId($parent->getId());
            $unit->setCaseValue($value);
        }

        return $unit;
    }
    public static function createUnit2($parent,$value) {
        $unit = new ProductPartition();
        $unit->setPartitionType(ProductPartitionType::UNIT);

        // The root node has neither a parent nor a value
            $unit->setParentCriterionId($parent);
            $unit->setCaseValue($value);

        return $unit;
    }



googleadsapi...@google.com

unread,
Mar 4, 2019, 10:21:48 AM3/4/19
to AdWords API and Google Ads API Forum
Hi Ryan,

Glad that you were able to resolve the issue. Thanks for sharing your code snippet. It will be useful for other users running into the same problem.

Thanks,
Sreelakshmi, AdWords API Team

=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:
    http://googleadsdeveloper.blogspot.com/search/label/adwords_api
    https://developers.google.com/adwords/api/community/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~

Hans Henrik Søllested

unread,
Apr 9, 2019, 6:06:19 PM4/9/19
to AdWords API and Google Ads API Forum
Hi. I'm struggeling with making a subdivision to a brand. Can you provide full example of you code? It seems you found a solution to what I'm trying to do. 

googleadsapi...@google.com

unread,
Apr 10, 2019, 1:37:25 AM4/10/19
to adwor...@googlegroups.com
Hi,

You may refer to this section of our shopping campaigns guide and also to this example code (PHP) on how to create subdivision using ProductBrand. I hope this helps.

Thanks and regards,
Peter
Google Ads API Team


=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog and discussion group:

Was your question answered? Please rate your experience with us by taking a short survey.
If not -- reply to this email and tell us what else we can do to help.

Take Survey

Also find us on our blog and discussion group:
http://googleadsdeveloper.blogspot.com/search/label/adwords_api
https://developers.google.com/adwords/api/community/

--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
Also find us on our blog:
https://googleadsdeveloper.blogspot.com/
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
 
You received this message because you are subscribed to the Google
Groups "AdWords API and Google Ads API Forum" group.
To post to this group, send email to adwor...@googlegroups.com
To unsubscribe from this group, send email to
adwords-api+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/adwords-api?hl=en
---
You received this message because you are subscribed to the Google Groups "AdWords API and Google Ads API Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscribe@googlegroups.com.
Visit this group at https://groups.google.com/group/adwords-api.
To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/d5bb97f5-47f3-4803-a52d-f6f897f033cd%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
Reply all
Reply to author
Forward
0 new messages