Error while trying to add a LogicalUserList

169 views
Skip to first unread message

Damien

unread,
Jul 16, 2015, 8:56:54 AM7/16/15
to adwor...@googlegroups.com
Hi,

I am currently working on creating Remarketing lists. I am using the Google AdWords API's Python libraries.

I needed to create a LogicalUserList combining two ExpressionRuleUserList. This is the error I got:
suds.WebFault: Server raised fault: 'Cannot construct an instance of com.google.ads.api.services.datax.userlists.LogicalUserListOperand because it is abstract.  You are probably missing an @Uses annotation while invoking public abstract com.google.ads.api.services.datax.userlists.UserListReturnValue com.google.ads.api.services.datax.adwordsuserlist.AdwordsUserListService.mutate(java.util.List) throws com.google.ads.api.services.common.error.ApiException with params [[com.google.ads.api.services.datax.adwordsuserlist.v201502.jaxbgen.UserListOperation@16687106]].'

My source code:
#!/usr/bin/python
#coding=UTF-8

from datetime import date
from datetime import datetime
from datetime import timedelta
from googleads import adwords

(...)

def createNewList(client, list_a, list_b):
 
# Initialize appropriate service.
  adwords_user_list_service
= client.GetService(
     
'AdwordsUserListService', version='v201502')


  rules
= [
     
{
         
'ruleOperands': [list_a],
         
'operator': 'ALL'
     
},
     
{
         
'ruleOperands': [list_b],
         
'operator': 'NONE'
     
}
 
]


 
# Create the user list with no restrictions on site visit date.
  combination_user_list
= {
     
'xsi_type': 'LogicalUserList',
     
'name': 'Bouncers list created at %s'
             
% datetime.today().strftime('%Y%m%d %H:%M:%S'),
     
'description': 'Users who visited list A but not B',
     
'rules': rules
     
#'startDate': today.strftime('%Y%m%d'),
     
#'endDate': end_date.strftime('%Y%m%d')
 
}


 
# Create operations to add the user lists.
  operations
= [
     
{
         
'operand': user_list,
         
'operator': 'ADD',
     
} for user_list in [combination_user_list]
 
]


 
# Submit the operations.
  user_lists
= adwords_user_list_service.mutate(operations)


 
# Display results.
 
for user_list in user_lists['value']:
   
print (('User list added with ID %d, name "%s", status "%s", list type'
           
' "%s", accountUserListStatus "%s", description "%s".') %
           
(user_list['id'], user_list['name'],
            user_list
['status'], user_list['listType'],
            user_list
['accountUserListStatus'], user_list['description']))



adwords_client = adwords.AdWordsClient.LoadFromStorage()

createNewList(adwords_client, list_a, list_b)

With list_a and list_b being lists I previously created.

Can anybody tell me what's wrong?

Alternatively, how is it possible to reproduce the "Visitors of a page who did not visit another page" behaviour with the API? The only way seemed to used combination lists but even is failing (see the error above)...


Thanks for your help,

Damien

Josh Radcliff (AdWords API Team)

unread,
Jul 17, 2015, 9:26:44 AM7/17/15
to adwor...@googlegroups.com, damien...@busbud.com
Hi Damien,

In the past, I've seen this error when the SOAP XML was malformed. Could you post your request XML with sensitive information removed (such as your developer token) so I can check it?

Thanks,
Josh, AdWords API Team

Damien

unread,
Jul 17, 2015, 2:36:37 PM7/17/15
to adwor...@googlegroups.com, damien...@busbud.com
Hi Josh,

Here is the Python logger output, you can find the XML request below (all sensitive information replaced by "[removed]"):

DEBUG:suds.transport.http:opening (https://adwords.google.com/api/adwords/rm/v201502/AdwordsUserListService?wsdl)
DEBUG
:suds.transport.http:sending:
URL
: https://adwords.google.com/api/adwords/rm/v201502/AdwordsUserListService
HEADERS
: {'Content-Type': 'text/xml; charset=utf-8', 'Authorization': 'Bearer [removed]', 'SOAPAction': b'""', 'Content-type': 'text/xml; charset=utf-8', 'Soapaction': b'""'}
MESSAGE
:
b
'<?xml version="1.0" encoding="UTF-8"?><SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:tns="https://adwords.google.com/api/adwords/rm/v201502" xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201502" xmlns:ns0="http://schemas.xmlsoap.org/soap/envelope/" xmlns:ns1="https://adwords.google.com/api/adwords/rm/v201502" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"><SOAP-ENV:Header><tns:RequestHeader><tns:clientCustomerId xmlns:tns="https://adwords.google.com/api/adwords/cm/v201502">[removed]</tns:clientCustomerId><tns:developerToken xmlns:tns="https://adwords.google.com/api/adwords/cm/v201502">[removed]</tns:developerToken><tns:userAgent xmlns:tns="https://adwords.google.com/api/adwords/cm/v201502">[removed] (AwApi-Python, googleads/3.5.0, Python/3.4.3)</tns:userAgent><tns:validateOnly xmlns:tns="https://adwords.google.com/api/adwords/cm/v201502">false</tns:validateOnly><tns:partialFailure xmlns:tns="https://adwords.google.com/api/adwords/cm/v201502">false</tns:partialFailure></tns:RequestHeader></SOAP-ENV:Header><ns0:Body><ns1:mutate><ns1:operations><ns2:operator>ADD</ns2:operator><ns1:operand xsi:type="ns1:LogicalUserList"><ns1:name>[removed] list created at 20150717 14:18:00</ns1:name><ns1:description>Users who visited list A but not B, C and D</ns1:description><ns1:UserList.Type>LogicalUserList</ns1:UserList.Type><ns1:rules><ns1:operator>ALL</ns1:operator><ns1:ruleOperands xsi:type="ns1:ExpressionRuleUserList"><ns1:id>102489659</ns1:id><ns1:isReadOnly>false</ns1:isReadOnly><ns1:name>List A created at 20150717 14:17:57</ns1:name><ns1:description>Users who visited a page where URL contains [removed]</ns1:description><ns1:status>OPEN</ns1:status><ns1:accessReason>OWNED</ns1:accessReason><ns1:accountUserListStatus>ACTIVE</ns1:accountUserListStatus><ns1:membershipLifeSpan>30</ns1:membershipLifeSpan><ns1:listType>RULE_BASED</ns1:listType><ns1:UserList.Type>ExpressionRuleUserList</ns1:UserList.Type><ns1:rule><ns1:groups><ns1:items><ns1:StringRuleItem><ns1:key><ns1:name>url__</ns1:name></ns1:key><ns1:op>CONTAINS</ns1:op><ns1:value>[removed]</ns1:value></ns1:StringRuleItem></ns1:items></ns1:groups></ns1:rule></ns1:ruleOperands></ns1:rules><ns1:rules><ns1:operator>NONE</ns1:operator><ns1:ruleOperands xsi:type="ns1:ExpressionRuleUserList"><ns1:id>102489779</ns1:id><ns1:isReadOnly>false</ns1:isReadOnly><ns1:name>List B created at 20150717 14:17:58</ns1:name><ns1:description>Users who visited a page where URL contains [removed]</ns1:description><ns1:status>OPEN</ns1:status><ns1:accessReason>OWNED</ns1:accessReason><ns1:accountUserListStatus>ACTIVE</ns1:accountUserListStatus><ns1:membershipLifeSpan>30</ns1:membershipLifeSpan><ns1:listType>RULE_BASED</ns1:listType><ns1:UserList.Type>ExpressionRuleUserList</ns1:UserList.Type><ns1:rule><ns1:groups><ns1:items><ns1:StringRuleItem><ns1:key><ns1:name>url__</ns1:name></ns1:key><ns1:op>CONTAINS</ns1:op><ns1:value>[removed]</ns1:value></ns1:StringRuleItem></ns1:items></ns1:groups></ns1:rule></ns1:ruleOperands><ns1:ruleOperands xsi:type="ns1:ExpressionRuleUserList"><ns1:id>102489899</ns1:id><ns1:isReadOnly>false</ns1:isReadOnly><ns1:name>List C created at 20150717 14:17:58</ns1:name><ns1:description>Users who visited a page where URL contains [removed]</ns1:description><ns1:status>OPEN</ns1:status><ns1:accessReason>OWNED</ns1:accessReason><ns1:accountUserListStatus>ACTIVE</ns1:accountUserListStatus><ns1:membershipLifeSpan>30</ns1:membershipLifeSpan><ns1:listType>RULE_BASED</ns1:listType><ns1:UserList.Type>ExpressionRuleUserList</ns1:UserList.Type><ns1:rule><ns1:groups><ns1:items><ns1:StringRuleItem><ns1:key><ns1:name>url__</ns1:name></ns1:key><ns1:op>CONTAINS</ns1:op><ns1:value>[removed]</ns1:value></ns1:StringRuleItem></ns1:items></ns1:groups></ns1:rule></ns1:ruleOperands><ns1:ruleOperands xsi:type="ns1:ExpressionRuleUserList"><ns1:id>102490019</ns1:id><ns1:isReadOnly>false</ns1:isReadOnly><ns1:name>List D created at 20150717 14:17:59</ns1:name><ns1:description>Users who visited a page where URL contains [removed]</ns1:description><ns1:status>OPEN</ns1:status><ns1:accessReason>OWNED</ns1:accessReason><ns1:accountUserListStatus>ACTIVE</ns1:accountUserListStatus><ns1:membershipLifeSpan>30</ns1:membershipLifeSpan><ns1:listType>RULE_BASED</ns1:listType><ns1:UserList.Type>ExpressionRuleUserList</ns1:UserList.Type><ns1:rule><ns1:groups><ns1:items><ns1:StringRuleItem><ns1:key><ns1:name>url__</ns1:name></ns1:key><ns1:op>CONTAINS</ns1:op><ns1:value>[removed]</ns1:value></ns1:StringRuleItem></ns1:items></ns1:groups></ns1:rule></ns1:ruleOperands></ns1:rules></ns1:operand></ns1:operations></ns1:mutate></ns0:Body></SOAP-ENV:Envelope>'
ERROR
:suds.client:<suds.sax.document.Document object at 0x10b29f4e0>

Thank you for your help,

Damien

Josh Radcliff (AdWords API Team)

unread,
Jul 20, 2015, 10:24:21 AM7/20/15
to adwor...@googlegroups.com, damien...@busbud.com
Hi Damien,

I think the issue here is your ruleOperands. This attribute should be a list of LogicalUserListOperands, each of which in turn has a child UserList element.

So instead of:
          <ns1:rules>
            <ns1:operator>ALL</ns1:operator>
            <ns1:ruleOperands xsi:type="ns1:ExpressionRuleUserList">
              <ns1:id>102489659</ns1:id>

your request should look like:
          <ns1:rules>
            <ns1:operator>ALL</ns1:operator>
            <ns1:ruleOperands>
              <UserList xsi:type="ns1:ExpressionRuleUserList">
                <ns1:id>102489659</ns1:id>
    
Please give that a try and let me know if you run into any other issues.

Thanks,
Josh, AdWords API Team

Damien

unread,
Jul 20, 2015, 1:50:01 PM7/20/15
to adwor...@googlegroups.com, damien...@busbud.com
Hi Josh,

Thank you very much, this solved my problem and I've been able to successfully create my LogicalUserList.

Damien

iukhn...@gmail.com

unread,
Mar 2, 2018, 7:15:13 PM3/2/18
to AdWords API Forum
hi, what you exactly changed in your pythone code?

Josh Radcliff (AdWords API Team)

unread,
Mar 5, 2018, 9:00:46 AM3/5/18
to AdWords API Forum
Hi,

Could you check out the add_rule_based_user_lists.py example and then let me know if that doesn't clear up your question?

Thanks,
Josh, AdWords API Team

Josh Radcliff (AdWords API Team)

unread,
Mar 5, 2018, 9:35:01 AM3/5/18
to AdWords API Forum
Hi,

Sorry, I just realized I sent you an example for rule based user lists. I'll look into this and try to provide you with some Python snippets to help.

In the meantime, Damien, if you have a snippet that could help, please share it here.

Thanks,
Josh, AdWords API Team

Josh Radcliff (AdWords API Team)

unread,
Mar 5, 2018, 1:02:36 PM3/5/18
to AdWords API Forum
Hi,

I'm not much of a Python expert, so please bear with me on formatting and style, but the following snippet worked for me:

  rule = {
      'operator': 'ALL',
      'ruleOperands': [
          {
              'UserList': {
                  'xsi_type': 'BasicUserList',
                  'id': INSERT_USER_LIST_ID_A_HERE,
              }
          },
          {
              'UserList': {
                  'xsi_type': 'BasicUserList',
                  'id': INSERT_USER_LIST_ID_B_HERE,
              }
          }
      ]
  }

  # Construct operations and add a user list.
  operations = [
      {
          'operator': 'ADD',
          'operand': {
              'xsi_type': 'LogicalUserList',
              'name': 'Logical #%s' % uuid.uuid4(),
              'description': 'Logical test',
              'rules': [rule],
          }
      }
  ]

Could you give that a try and let me know if you still encounter issues?

Thanks,
Josh, AdWords API Team

Reply all
Reply to author
Forward
0 new messages