Adding an Audience list to a campaign using google ads python API

56 views
Skip to first unread message

Kareem Emad

unread,
Aug 7, 2019, 3:24:34 AM8/7/19
to AdWords API and Google Ads API Forum

I'm trying to attach an audience list - which I have already created on Google ads using the python api - to an existing campaign on the same Google ads account. I have both the ID of the campaign and the ID of the audience list, but I did not find any clear example in the documentation on how to attach an audience list to campaign.


Can anyone provide example on how the json object to be sent to google ads is structured to request adding an audience list to a campaign?


I tried to follow the reference guidelines in the documentation to compose the request json format object needed to be sent to add an audience list to a certain campaign .

```python

from googleads import adwords
import yaml

data = {} # should contain credentials for authentication

auth_data = yaml.dump(data)
client = adwords.AdWordsClient.LoadFromString(auth_data)

campaign_criterion_list_service = client.GetService(
    'CampaignCriterionService', version='v201809')

 operations = [ 
    { 
        'operand': { 
            'campaignId': 1982314222, # some campaign in my account

            'criterion': { 
                'type': 'USER_LIST',
                'id': 823895895,# an existing audience list on my  google ads account
            }, 
            'campaignCriterionStatus': 'ACTIVE' 
        }, 
        'operator': 'ADD', 
    } 
 ]
campaign_criterion_list_service.mutate(operations)

```

But it fails providing the error

```
GoogleAdsServerFault: [CampaignCriterionError.CONCRETE_TYPE_REQUIRED @ operations[0].operand.criterion]
```


And also searched for similar problems, found this solution in Java,but I did not succeed into coming up with a similar one in python.

Google Ads API Forum Advisor Prod

unread,
Aug 7, 2019, 4:55:51 AM8/7/19
to adwor...@googlegroups.com
Hi Kareem,

Thank you for reaching out.

My apologies as we do not have an exact Python sample code on what you are looking for. However, you can refer to this sample code instead on positively targeting campaign criteria. You can just modify the code a little bit to cater the CriterionUserList.

The CONCRETE_TYPE_REQUIRED error usually occurs if you are not specifying the type of Criterion that you are trying to mutate. Can you specify this in your request and give this a try on your end? Once you have done so, in your SOAP logs, it should look similar to the one below:

'xsi_type': 'Userlist'

If you're still encountering any issues after, kindly provide the complete SOAP request and response logs as well. You may enable logging by referring to this guide. Kindly use the reply privately to author option. 

Regards,
Dannison
Google Ads API Team

ref:_00D1U1174p._5001UEIAsC:ref
Reply all
Reply to author
Forward
0 new messages