[Python] Adwords API - Product Partition

255 views
Skip to first unread message

Kevin Weitzner

unread,
Oct 19, 2018, 2:39:25 PM10/19/18
to AdWords API and Google Ads API Forum
Greetings,

I'm attempting to modify the add_product_partition_tree.py (https://github.com/googleads/googleads-python-lib/blob/master/examples/adwords/v201806/shopping/add_product_partition_tree.py) example file to create a product group with a single PLAID - and every other item to be excluded from that group.

Interestingly, the script straight from Github errors -- but I've been trying to modify it to accomplish what I am looking to do, but no matter how I approach it, I can't quite figure it out.  

Almost any method I use to accomplish this results in the error:
googleads.errors.GoogleAdsServerFault: [AdGroupCriterionError.PRODUCT_PARTITION_ALREADY_EXISTS @ operations[0].operand.criterion, AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[1].operand.criterion.parentCriterionId; trigger:'TempCriterionId{id=1}', AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[2].operand.criterion.parentCriterionId; trigger:'TempCriterionId{id=1}', AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[3].operand.criterion.parentCriterionId; trigger:'TempCriterionId{id=1}', AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[4].operand.criterion.parentCriterionId; trigger:'TempCriterionId{id=2}', AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[5].operand.criterion.parentCriterionId; trigger:'TempCriterionId{id=2}', AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[6].operand.criterion.parentCriterionId; trigger:'TempCriterionId{id=2}', AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[7].operand.criterion.parentCriterionId; trigger:'TempCriterionId{id=3}', AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[8].operand.criterion.parentCriterionId; trigger:'TempCriterionId{id=3}']

---

From looking at the various posts on the forum, and the java api.. I think I need to delete all product partitions - and then try to build out the product partitions .. but I can't find out how to do this using the python library.  

Is there anybody who has a starting point that I can use to make adjustments on?

Thanks,
Kevin

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Oct 19, 2018, 9:05:03 PM10/19/18
to AdWords API and Google Ads API Forum
Hi Kevin,

From the error, it looks like the subdivision creation is failing as there is already a product partition. The subsequent nodes seems to fail as the subdivision creation failed. Could you please confirm if you were creating the ad group via Google Ads UI? If so, you will need to first remove the default product partition and then retry to create your new product partition. This post should be helpful. If you want to do this in a new ad group, you could create one via the API and then use the code sample that you shared to create the product partition. Please give this a try and let me know if you face any issues.

Thanks,
Sreelakshmi, AdWords API Team

Kevin Weitzner

unread,
Oct 20, 2018, 12:04:33 AM10/20/18
to AdWords API and Google Ads API Forum
Hi,

It's not clear exactly how to do this - can I do it via this library without an external report call? In the c# library it looks like there exists a method to do this rather easily -

" // Build a new ProductPartitionTree using the ad group's current set of criteria.
ProductPartitionTree partitionTree =
ProductPartitionTree.DownloadAdGroupTree(user, adGroupId);

Console.WriteLine("Original tree: {0}", partitionTree);

// Clear out any existing criteria.
ProductPartitionNode rootNode = partitionTree.Root.RemoveAllChildren();"


I can't find any examples of this sort of method - the example you showed looks like I have to specify the ID. I will try this on Monday, but it doesn't really look to be as simple. Is there a way in the python library to display the tree, and remove all children, or do I have to run a report., grab all IDs and remove via an operation?

Kevin Weitzner

unread,
Oct 22, 2018, 2:44:43 PM10/22/18
to AdWords API and Google Ads API Forum

I was able to remove the existing partition via the code:


adgroup_criterion_service = client.GetService(
'AdGroupCriterionService', version='v201806')

helper = ProductPartitionHelper(adgroup_id)
division_old = {
'xsi_type': 'ProductPartition',
'partitionType': 'SUBDIVISION',
'id': '293946777986'
}

adgroup_criterion_old = {
'xsi_type': 'BiddableAdGroupCriterion',
'adGroupId': adgroup_id,
'criterion': division_old
}
operation = {
'operator': 'REMOVE',
'operand': adgroup_criterion_old
}


# Make the mutate request
result = adgroup_criterion_service.mutate(operation)


I am still struggling with creating the proper mutate requests for a single product partition, and everything else in the other case.  

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Oct 22, 2018, 7:15:48 PM10/22/18
to AdWords API and Google Ads API Forum
Hello Kevin,

Glad that you were able to remove the existing product partition. What issue are you facing? Could you please share the error that you are getting along with your SOAP logs? You can use reply privately to the author option while responding.

Kevin Weitzner

unread,
Oct 22, 2018, 8:10:38 PM10/22/18
to AdWords API and Google Ads API Forum
I have sent you some details privately.  Thanks

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Oct 23, 2018, 7:57:25 PM10/23/18
to AdWords API and Google Ads API Forum
Hi Kevin, 

Yes, I did get the details that you had shared. If you are looking for a product partition tree as attached in the screenshot, you could use the code sample attached. The "empty" caseValue of the correct type is required to represent "all other values". Please check here for more details. You can refer to this sample to create a shopping campaign and the ad group. Please let me know if you have any additional questions. 
ProductPartition.png
add_product_partition_tree.py

Kevin Weitzner

unread,
Oct 26, 2018, 4:47:18 PM10/26/18
to AdWords API and Google Ads API Forum
Hi Sreelakshmi,

Sorry for the delay, I've been working on other projects this week.   The image you've attached does not appear to show up.

I am trying to modify the sample you've given to do a small test, and  still running into an error - if I exclude the parentCriterionId:-1, it gives an error that I require one.  If I put in the -1 I get the error:googleads.errors.GoogleAdsServerFault: [AdGroupCriterionError.PRODUCT_PARTITION_DOES_NOT_EXIST @ operations[1].operand.criterion.parentCriterionId; trigger:'TempCriterionId{id=1}']


The mutate request operations look like this:
operations = [{
'operator': 'ADD',
'operand': {

'xsi_type': 'BiddableAdGroupCriterion',
'adGroupId': adgroup_id,
        # Make sure that caseValue and parentCriterionId are left unspecified.
# This makes this partition as generic as possible to use as a
# fallback when others don't match.
'criterion': {
'xsi_type': 'ProductPartition',
'partitionType': 'UNIT'
},
'biddingStrategyConfiguration': {
'bids': [{
'xsi_type': 'CpcBid',
'bid': {
'microAmount': 500000
}
}]
}
}
},
{
'operator': 'ADD',
'operand': {

'xsi_type': 'BiddableAdGroupCriterion',
'adGroupId': adgroup_id,
            'criterion': {
'xsi_type': 'ProductPartition',
'partitionType': 'UNIT',
'parentCriterionId':-1,
'caseValue':
{'xsi_type':'ProductOfferId',
'value': '2237847'
}
},
'biddingStrategyConfiguration': {
'bids': [{
'xsi_type': 'CpcBid',
'bid': {
'microAmount': 500000
}
}]
}
},

}

]


I think I'm almost there.. but I am not sure of how to get the appropriate parentCriterionId in order for this to succeed.  Please let me know if you want the soap requst logs.


Kevin Weitzner

unread,
Oct 26, 2018, 4:54:12 PM10/26/18
to AdWords API and Google Ads API Forum
Additionally -- the end goal is to be able to built it out like the attached image.
u7P8Dnz.png

Kevin Weitzner

unread,
Oct 26, 2018, 5:37:44 PM10/26/18
to AdWords API and Google Ads API Forum
I figured it out, using the pre-built definitions in the example.

For anybody else who needs to do this in Python - you can build it off this -- include the class ProductPartitionHelper - pass it a list of PLA IDs and it will create them.   There is probably a better way to do this - but this should get you going if you need to segment by ID rather than conditions/categories like in the example.


def main(client, adgroup_id, PLAList):
"""Runs the example."""
  adgroup_criterion_service = client.GetService(
'AdGroupCriterionService', version='v201806')

helper = ProductPartitionHelper(adgroup_id)
  root = helper.CreateSubdivision()

for pla in PLAList:
new_product = {
'xsi_type' : 'ProductOfferId',
'value' : ''
}
new_product['value'] = pla
helper.CreateUnit(root, new_product, 200000)

other_products = {
'xsi_type': 'ProductOfferId',
}

helper.CreateUnit(
root, other_products)


# Make the mutate request
  result = adgroup_criterion_service.mutate(helper.GetOperations())

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Oct 26, 2018, 8:58:10 PM10/26/18
to AdWords API and Google Ads API Forum
Hi Kevin, 

Glad that you were able to find the solution. You are right, to partition with the offer id, you will need to use the ProductOfferId dimension. Here is the list of product dimensions that you can use while creating product partitions. 
Reply all
Reply to author
Forward
0 new messages