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?
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.
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.
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())