Product Partition Tree Enumeration Exception

138 views
Skip to first unread message

Sarah Gilmore

unread,
Nov 21, 2014, 9:21:30 AM11/21/14
to adwor...@googlegroups.com
Hi there

I'm having trouble getting the Product Partition script to work in PHP. I'm using the example in the SDK. I've solved some errors by creating a new Adgroup from scratch within the API, but I get the following exception when I run the script:

An error has occurred: Unmarshalling Error: cvc-enumeration-valid: Value 'shirts' is not facet-valid with respect to enumeration '[UNKNOWN, BIDDING_CATEGORY_L1, BIDDING_CATEGORY_L2, BIDDING_CATEGORY_L3, BIDDING_CATEGORY_L4, BIDDING_CATEGORY_L5, BRAND, CANONICAL_CONDITION, CUSTOM_ATTRIBUTE_0, CUSTOM_ATTRIBUTE_1, CUSTOM_ATTRIBUTE_2, CUSTOM_ATTRIBUTE_3, CUSTOM_ATTRIBUTE_4, OFFER_ID, PRODUCT_TYPE_L1, PRODUCT_TYPE_L2, PRODUCT_TYPE_L3, PRODUCT_TYPE_L4, PRODUCT_TYPE_L5]'

I'm assuming this means that I'm entering invalid categories/making an invalid tree but I can't work out how. I've checked that the categories I'm using are in the product feed. I don't work much with Adwords itself - just the API - so any advice would be appreciated


function addProductPartitionTreeExample(AdWordsUser $user, $adGroupId) {

  // Get the AdGroupCriterionService, which loads the required classes.
  $adGroupCriterionService = $user->GetService('AdGroupCriterionService',
        ADWORDS_VERSION);
  $helper = new ProductPartitionHelper($adGroupId);
  // The most trivial partition tree has only a unit node as the root:
  //   $helper->createUnit(null, null, 100000);
  $root = $helper->createSubdivision();
  $helper->createUnit($root, new ProductCanonicalCondition('NEW'), 200000);
  $helper->createUnit($root, new ProductCanonicalCondition('USED'), 100000);
  $otherCondition = $helper->createSubdivision($root,
      new ProductCanonicalCondition());
  $helper->createUnit($otherCondition, new ProductType('shirts'), 200000);
  $helper->createUnit($otherCondition, new ProductType('footwear'), 100000);
  $otherBrand =
      $helper->createSubdivision($otherCondition, new ProductType());
  // The value for the bidding category is a fixed ID for the 'Luggage & Bags'
  // category. You can retrieve IDs for categories from the ConstantDataService.
  // See the 'GetProductCategoryTaxonomy' example for more details.
  $helper->createUnit($otherBrand,
      new ProductBiddingCategory('BIDDING_CATEGORY_L1',
      '-3817140941569278349'), 750000);//for clothes
  $helper->createUnit($otherBrand,
      new ProductBiddingCategory('BIDDING_CATEGORY_L1'), 110000);
  // Make the mutate request.
  $result = $adGroupCriterionService->mutate($helper->getOperations());
  $children = array();
  $rootNode = null;
  // For each criterion, make an array containing each of its children
  // We always create the parent before the child, so we can rely on that here
  foreach ($result->value as $adGroupCriterion) {
    $children[$adGroupCriterion->criterion->id] = array();
    if (isset($adGroupCriterion->criterion->parentCriterionId)) {
      $children[$adGroupCriterion->criterion->parentCriterionId][] =
          $adGroupCriterion->criterion;
    } else {
      $rootNode = $adGroupCriterion->criterion;
    }
  }
  // Show the tree
  displayTree($rootNode, $children);

}

Thanks

Josh Radcliff (AdWords API Team)

unread,
Nov 21, 2014, 11:52:00 AM11/21/14
to adwor...@googlegroups.com
Hi,

Similar to ProductBiddingCategory, when creating a ProductType criterion, you'll want to pass both:
  1. The product type level (enum) - this is on the type attribute and should match one of the PRODUCT_TYPE_Lx enums of ProductDimensionType
  2. The product type value (string) - this is on the value attribute
In your calls to the ProductType constructor you are only passing the value, but the constructor expects the type and the value, in that order. For example, for your "shirts" product type, you could modify your constructor call to:

new ProductType('PRODUCT_TYPE_L1', 'shirts')

Please give that a try and let me know if you're still running into errors.

Cheers,
Josh, AdWords API Team

Sarah Gilmore

unread,
Nov 24, 2014, 5:42:55 AM11/24/14
to adwor...@googlegroups.com
Hi Josh

I've tried adding product level into the constuctor but get the following error:

An error has occurred: [RequiredError.REQUIRED @ operations[3].operand.criterion.caseValue.type]

I've tried reducing it down to the bare minimum (as below) but stillt this error. All I really want is a tree to divide by product type but when I do this, it says 'product partition already exists' (despite being a brand new adgroup created within the API)

Here is my current code, any other help appreciated

Thanks

  $adGroupCriterionService = $user->GetService('AdGroupCriterionService',
        ADWORDS_VERSION);
  $helper = new ProductPartitionHelper($adGroupId);
  $root = $helper->createSubdivision();
  $helper->createUnit($root, new ProductCanonicalCondition('NEW'), 200000);
  $helper->createUnit($root, new ProductCanonicalCondition('USED'), 100000);
  
  $otherCondition = $helper->createSubdivision($root, new ProductType());
  $helper->createUnit($otherCondition, new ProductType('PRODUCT_TYPE_L1','shirts'), 200000);
  $helper->createUnit($otherCondition, new ProductType('PRODUCT_TYPE_L1','footwear'), 100000);

  $result = $adGroupCriterionService->mutate($helper->getOperations());
  $children = array();
  $rootNode = null;

Josh Radcliff (AdWords API Team)

unread,
Nov 24, 2014, 9:07:36 AM11/24/14
to adwor...@googlegroups.com
Hi,

At every level of the product partition tree, all product partitions need to have the same type of caseValue (ProductDimension subclass) -- see our Shopping Campaigns guide for details.

In your example, you are trying to create a tree that looks like this:

ROOT <-- subdivision
  -- ProductCanonicalCondition condition NEW <-- unit
  -- ProductCanonicalCondition condition USED <-- unit
  -- ProductType type null, value null <-- subdivision
    -- ProductType type L1, value 'shirts' <-- unit
    -- ProductType type L1, value 'footwear' <-- unit

There are two issues with this tree:

1. You have a combination of ProductCanonicalConditions and ProductType at the first level below the root. For the 'other' condition at level one, you need to have a ProductCanonicalCondition with a null condition because all partitions at a level need to have the same type of caseValue.

2. The ProductType you have at level one needs to have a type value (one of L1, L2, L3, L4, L5).

One example of a valid tree you could create using the dimensions in your example is:

ROOT <-- subdivision
  -- ProductCanonicalCondition condition NEW <-- unit
  -- ProductCanonicalCondition condition USED <-- unit
  -- ProductCanonicalCondition condition null <-- subdivision
    -- ProductType type L1, value 'shirts' <-- unit
    -- ProductType type L1, value 'footwear' <-- unit
    -- ProductType type L1, value null <-- unit

You could also create a tree like this if you wanted to break down each of NEW and USED by product type L1 'shirts' and 'footwear'.

ROOT <-- subdivision
  -- ProductCanonicalCondition condition NEW <-- subdivision
    -- ProductType type L1, value 'shirts' <-- unit
    -- ProductType type L1, value 'footwear' <-- unit
  -- ProductCanonicalCondition condition USED <-- subdivision
    -- ProductType type L1, value 'shirts' <-- unit
    -- ProductType type L1, value 'footwear' <-- unit
    -- ProductType type L1, value null <-- unit
  -- ProductCanonicalCondition condition null <-- unit

Please give that a try and let me know if you still have questions.

Thanks,
Josh, AdWords API Team

Sarah Gilmore

unread,
Nov 25, 2014, 7:01:21 AM11/25/14
to adwor...@googlegroups.com
Hi Josh

That's great, I have managed to implement the tree that I want. Just a few little misunderstandings. Thanks for your help

Sarah
Reply all
Reply to author
Forward
0 new messages