Attached my python file and the soap log file.

On Wednesday, 10 April 2019 21:16:08 UTC+2, googleadsapi-forumadvisor wrote:
>
> Hello Ben,
>
> Thank you for sharing the logs. The error indicates that you're missing 
> the CaseValue. Each immediate child of a subdivision must have a caseValue 
> of the same ProductDimension subtype. Only the root node doesn't have a 
> caseValue. Please check this guide 
> <https://developers.google.com/adwords/api/docs/guides/shopping#partitioning> 
> for 
> more information.
>
> Regards,
> Bharani, Google Ads API Team
>
> =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
> Also find us on our blog and discussion group:
>     https://ads-developers.googleblog.com/search/label/google_ads_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 
> <https://support.google.com/google-ads/contact/survey_transactional?caseid=0-5303000025980&hl=en&ctx=1>
>
> 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 [email protected]
To unsubscribe from this group, send email to
[email protected]
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 [email protected].
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/f5add0c5-7b73-4137-a667-8048de59345b%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
from googleads import adwords
import logging              
import sys                  # to get parameters at run time
import pandas as pd         # to get data to exasol
import pyexasol             # write pd df to exasol
import config               # exasol credentials
from itertools import chain  
import time
import googleads

# settings for logging
logger = logging.getLogger('logger')
logger.setLevel(logging.INFO)
ch = logging.StreamHandler(sys.stdout)
ch.setLevel(logging.INFO)
formatter = logging.Formatter('%(asctime)s [%(levelname)s] - %(message)s', datefmt='%Y-%m-%d %H:%M:%S')
ch.setFormatter(formatter)
logger.addHandler(ch)

shooping_account_id = str(sys.argv[1]) # get adwords shopping account id from argument provided from shell script

ADGROUP_ID = '76723781948'


class ProductPartitionHelper(object):
  """A helper for creating ProductPartition trees."""
  logging.basicConfig(level=logging.INFO, format=googleads.util.LOGGER_FORMAT)
  logging.getLogger('googleads.soap').setLevel(logging.DEBUG)

  def __init__(self, adgroup_id):
    """Initializer.
    Args:
      adgroup_id: The ID of the AdGroup that we wish to attach the partition
                  tree to.
    """
    # The next temporary criterion ID to be used.
    # When creating our tree we need to specify the parent-child relationships
    # between nodes. However, until a criterion has been created on the server
    # we do not have a criterion ID with which to refer to it.
    # Instead we can specify temporary IDs that are specific to a single mutate
    # request. Once the criteria have been created they are assigned an ID as
    # normal and the temporary ID will no longer refer to it.
    # A valid temporary ID is any negative integer.
    self.next_id = -1
    # The set of mutate operations needed to create the current tree.
    self.operations = []
    self.adgroup_id = adgroup_id

  def CreateSubdivision(self, parent=None, value='Other'):
    """Creates a subdivision node.
    Args:
      parent: The node that should be this node's parent.
      value: The value being partitioned on.
    Returns:
      A new subdivision node.
    """
    division = {
        'xsi_type': 'ProductPartition',
        'partitionType': 'SUBDIVISION',
        'id': str(self.next_id)
    }

    # The root has neither a parent nor a value.
    if parent is not None:
      division['parentCriterionId'] = parent['id']
      division['caseValue'] = value  ############## INPUT

    adgroup_criterion = {
        'xsi_type': 'BiddableAdGroupCriterion',
        'adGroupId': self.adgroup_id,
        'criterion': division
    }

    self.CreateAddOperation(adgroup_criterion)
    self.next_id -= 1

    return division

  def CreateUnit(self, parent=None, value=None, bid_amount=None):
    """Creates a unit node.
    Args:
      parent: The node that should be this node's parent.
      value: The value being partitioned on.
      bid_amount: The amount to bid for matching products, in micros.
    Returns:
      A new unit node.
    """
    unit = {
        'xsi_type': 'ProductPartition',
        'partitionType': 'UNIT'
    }

    # The root node has neither a parent nor a value.
    if parent is not None:
      unit['parentCriterionId'] = parent['id']
      unit['caseValue'] = value  ############## INPUT

    if bid_amount is not None and bid_amount > 0:
      bidding_strategy_configuration = {
          'bids': [{
              'xsi_type': 'CpcBid',
              'bid': {
                  'xsi_type': 'Money',
                  'microAmount': str(bid_amount)
              }
          }]
      }

      adgroup_criterion = {
          'xsi_type': 'BiddableAdGroupCriterion',
          'biddingStrategyConfiguration': bidding_strategy_configuration
      }
    else:
      adgroup_criterion = {
          'xsi_type': 'NegativeAdGroupCriterion'
      }

    adgroup_criterion['adGroupId'] = self.adgroup_id
    adgroup_criterion['criterion'] = unit

    self.CreateAddOperation(adgroup_criterion)

    return unit

  def GetOperations(self):
    """Returns the set of mutate operations needed to create the current tree.
    Returns:
      The set of operations
    """
    return self.operations

  def CreateAddOperation(self, criterion):
    """Creates an AdGroupCriterionOperation for the given criterion.
    Args:
      criterion: The criterion we want to add.
    """
    operation = {
        'operator': 'ADD',
        'operand': criterion
    }

    self.operations.append(operation)


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

  helper = ProductPartitionHelper(adgroup_id)

  # The most trivial partition tree has only a unit node as the root, e.g.:
  #helper.CreateUnit(bid_amount=100000)

  root = helper.CreateSubdivision()
  
  
  new_product_canonical_condition = {
      'xsi_type': 'ProductCustomAttribute',
      'type': 'CUSTOM_ATTRIBUTE_1',
      'value': 'my attribute value'

  }

  other_product_canonical_condition = {
      'xsi_type': 'ProductCustomAttribute',
 #     'type': 'CUSTOM_ATTRIBUTE_1',
      'value': 'other'
  }
  
  
  helper.CreateUnit(root, new_product_canonical_condition, 100000)
  other_condition = helper.CreateSubdivision(
      root, other_product_canonical_condition)

  cool_product_brand = {
      'xsi_type': 'ProductBrand',
      'value': 'Brand'
  }

  other_product_brand = {
      'xsi_type': 'ProductBrand',
  }



  helper.CreateUnit(other_condition, cool_product_brand, 10000)
  other_brand = helper.CreateSubdivision(other_condition, other_product_brand)
  
  # Make the mutate request
  result = adgroup_criterion_service.mutate(helper.GetOperations())

  children = {}

  root_node = None ## input

  # 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.
  for adgroup_criterion in result['value']:
    children[adgroup_criterion['criterion']['id']] = []

    if 'parentCriterionId' in adgroup_criterion['criterion']:
      children[adgroup_criterion['criterion']['parentCriterionId']].append(
          adgroup_criterion['criterion'])
    else:
      root_node = adgroup_criterion['criterion']

if __name__ == '__main__':
  # Initialize client object.
  adwords_client = adwords.AdWordsClient.LoadFromStorage()
  adwords_client.SetClientCustomerId(shooping_account_id) # testing shopping account

  main(adwords_client, ADGROUP_ID)
[2019-04-10 06:23:21,400 - googleads.soap - INFO] Request made: Service: 
"AdGroupCriterionService" Method: "mutate" URL: 
"https://adwords.google.com/api/adwords/cm/v201809/AdGroupCriterionService";
[2019-04-10 06:23:21,401 - googleads.soap - DEBUG] Outgoing request: 
{'SOAPAction': '""', 'Content-Type': 'text/xml; charset=utf-8', 
'authorization': 'REDACTED'}
<soap-env:Envelope xmlns:soap-env="http://schemas.xmlsoap.org/soap/envelope/";>
  <soap-env:Header>
    <ns0:RequestHeader 
xmlns:ns0="https://adwords.google.com/api/adwords/cm/v201809";>
      <ns0:clientCustomerId>701-657-2509</ns0:clientCustomerId>
      <ns0:developerToken>REDACTED</ns0:developerToken>
      <ns0:userAgent>unknown (AwApi-Python, googleads/15.0.1, Python/3.7.1, 
zeep)</ns0:userAgent>
      <ns0:validateOnly>false</ns0:validateOnly>
      <ns0:partialFailure>false</ns0:partialFailure>
    </ns0:RequestHeader>
  </soap-env:Header>
  <soap-env:Body>
    <ns0:mutate xmlns:ns0="https://adwords.google.com/api/adwords/cm/v201809";>
      <ns0:operations>
        <ns0:operator>ADD</ns0:operator>
        <ns0:operand xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:BiddableAdGroupCriterion">
          <ns0:adGroupId>76723781948</ns0:adGroupId>
          <ns0:criterion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:ProductPartition">
            <ns0:id>-1</ns0:id>
            <ns0:partitionType>SUBDIVISION</ns0:partitionType>
          </ns0:criterion>
        </ns0:operand>
      </ns0:operations>
      <ns0:operations>
        <ns0:operator>ADD</ns0:operator>
        <ns0:operand xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:BiddableAdGroupCriterion">
          <ns0:adGroupId>76723781948</ns0:adGroupId>
          <ns0:criterion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:ProductPartition">
            <ns0:partitionType>UNIT</ns0:partitionType>
            <ns0:parentCriterionId>-1</ns0:parentCriterionId>
            <ns0:caseValue 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:ProductCustomAttribute">
              <ns0:type>CUSTOM_ATTRIBUTE_1</ns0:type>
              <ns0:value>my attribute value</ns0:value>
            </ns0:caseValue>
          </ns0:criterion>
          <ns0:biddingStrategyConfiguration>
            <ns0:bids xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:CpcBid">
              <ns0:bid>
                <ns0:microAmount>100000</ns0:microAmount>
              </ns0:bid>
            </ns0:bids>
          </ns0:biddingStrategyConfiguration>
        </ns0:operand>
      </ns0:operations>
      <ns0:operations>
        <ns0:operator>ADD</ns0:operator>
        <ns0:operand xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:BiddableAdGroupCriterion">
          <ns0:adGroupId>76723781948</ns0:adGroupId>
          <ns0:criterion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:ProductPartition">
            <ns0:id>-2</ns0:id>
            <ns0:partitionType>SUBDIVISION</ns0:partitionType>
            <ns0:parentCriterionId>-1</ns0:parentCriterionId>
            <ns0:caseValue 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:ProductCustomAttribute">
              <ns0:value>other</ns0:value>
            </ns0:caseValue>
          </ns0:criterion>
        </ns0:operand>
      </ns0:operations>
      <ns0:operations>
        <ns0:operator>ADD</ns0:operator>
        <ns0:operand xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:BiddableAdGroupCriterion">
          <ns0:adGroupId>76723781948</ns0:adGroupId>
          <ns0:criterion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:ProductPartition">
            <ns0:partitionType>UNIT</ns0:partitionType>
            <ns0:parentCriterionId>-2</ns0:parentCriterionId>
            <ns0:caseValue 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:ProductBrand">
              <ns0:value>Brand</ns0:value>
            </ns0:caseValue>
          </ns0:criterion>
          <ns0:biddingStrategyConfiguration>
            <ns0:bids xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:CpcBid">
              <ns0:bid>
                <ns0:microAmount>10000</ns0:microAmount>
              </ns0:bid>
            </ns0:bids>
          </ns0:biddingStrategyConfiguration>
        </ns0:operand>
      </ns0:operations>
      <ns0:operations>
        <ns0:operator>ADD</ns0:operator>
        <ns0:operand xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:BiddableAdGroupCriterion">
          <ns0:adGroupId>76723781948</ns0:adGroupId>
          <ns0:criterion xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:ProductPartition">
            <ns0:id>-3</ns0:id>
            <ns0:partitionType>SUBDIVISION</ns0:partitionType>
            <ns0:parentCriterionId>-2</ns0:parentCriterionId>
            <ns0:caseValue 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="ns0:ProductBrand"/>
          </ns0:criterion>
        </ns0:operand>
      </ns0:operations>
    </ns0:mutate>
  </soap-env:Body>
</soap-env:Envelope>

[2019-04-10 06:23:21,691 - googleads.soap - DEBUG] Incoming response: 
b'<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/";>\n  
<soap:Header>\n    <ResponseHeader 
xmlns="https://adwords.google.com/api/adwords/cm/v201809";>\n      
<requestId>000586271b2fabba0a375806530c085d</requestId>\n      
<serviceName>AdGroupCriterionService</serviceName>\n      
<methodName>mutate</methodName>\n      <operations>5</operations>\n      
<responseTime>115</responseTime>\n    </ResponseHeader>\n  </soap:Header>\n  
<soap:Body>\n    <soap:Fault>\n      <faultcode>soap:Client</faultcode>\n      
<faultstring>[RequiredError.REQUIRED @ 
operations[2].operand.criterion.caseValue.type]</faultstring>\n      <detail>\n 
       <ApiExceptionFault 
xmlns="https://adwords.google.com/api/adwords/cm/v201809";>\n          
<message>[RequiredError.REQUIRED @ 
operations[2].operand.criterion.caseValue.type]</message>\n          
<ApplicationException.Type>ApiException</ApplicationException.Type>\n          
<errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"; 
xsi:type="RequiredError">\n            
<fieldPath>operations[2].operand.criterion.caseValue.type</fieldPath>\n         
   <fieldPathElements>\n              <field>operations</field>\n              
<index>2</index>\n            </fieldPathElements>\n            
<fieldPathElements>\n              <field>operand</field>\n            
</fieldPathElements>\n            <fieldPathElements>\n              
<field>criterion</field>\n            </fieldPathElements>\n            
<fieldPathElements>\n              <field>caseValue</field>\n            
</fieldPathElements>\n            <fieldPathElements>\n              
<field>type</field>\n            </fieldPathElements>\n            <trigger/>\n 
           <errorString>RequiredError.REQUIRED</errorString>\n            
<ApiError.Type>RequiredError</ApiError.Type>\n            
<reason>REQUIRED</reason>\n          </errors>\n        </ApiExceptionFault>\n  
    </detail>\n    </soap:Fault>\n  </soap:Body>\n</soap:Envelope>\n'
[2019-04-10 06:23:21,692 - googleads.soap - WARNING] Error summary: 
{'faultMessage': '[RequiredError.REQUIRED @ 
operations[2].operand.criterion.caseValue.type]', 'requestId': 
'000586271b2fabba0a375806530c085d', 'serviceName': 'AdGroupCriterionService', 
'methodName': 'mutate', 'operations': '5', 'responseTime': '115'}
Traceback (most recent call last):
  File 
"/data/bi-python/google_shopping/lib64/python3.7/site-packages/googleads/common.py",
 line 1382, in MakeSoapRequest
    *packed_args, _soapheaders=soap_headers)['body']['rval']
  File 
"/data/bi-python/google_shopping/lib64/python3.7/site-packages/zeep/proxy.py", 
line 42, in __call__
    self._op_name, args, kwargs)
  File 
"/data/bi-python/google_shopping/lib64/python3.7/site-packages/zeep/wsdl/bindings/soap.py",
 line 132, in send
    return self.process_reply(client, operation_obj, response)
  File 
"/data/bi-python/google_shopping/lib64/python3.7/site-packages/zeep/wsdl/bindings/soap.py",
 line 194, in process_reply
    return self.process_error(doc, operation)
  File 
"/data/bi-python/google_shopping/lib64/python3.7/site-packages/zeep/wsdl/bindings/soap.py",
 line 299, in process_error
    detail=fault_node.find('detail'))
zeep.exceptions.Fault: [RequiredError.REQUIRED @ 
operations[2].operand.criterion.caseValue.type]

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "add_product_partition_tree_mod.py", line 213, in <module>
    main(adwords_client, ADGROUP_ID)
  File "add_product_partition_tree_mod.py", line 191, in main
    result = adgroup_criterion_service.mutate(helper.GetOperations())
  File 
"/data/bi-python/google_shopping/lib64/python3.7/site-packages/googleads/common.py",
 line 1394, in MakeSoapRequest
    e.detail, errors=error_list, message=e.message)
googleads.errors.GoogleAdsServerFault: [RequiredError.REQUIRED @ 
operations[2].operand.criterion.caseValue.type]
  • How to ... Ben
    • Ho... Ben
      • ... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum
        • ... Ben
          • ... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum
            • ... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum
              • ... Ben
              • ... Ben
                • ... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum
                • ... Ben
                • ... googleadsapi-forumadvisor via AdWords API and Google Ads API Forum

Reply via email to