Adding a list of Audience to some Campaign/AdGroups

928 views
Skip to first unread message

kuppa.j...@aaa-calif.com

unread,
Jan 27, 2017, 1:54:41 PM1/27/17
to AdWords API Forum
Hi Im using the Java API and am trying to figure out how to add an Audience to Adgroup/campaign. I have been able to successfully upload CRM email list to my account(s), However I do not see a example of adding audience to adgroup. Can I get pointed to an example or something of the sort? 

Shwetha Vastrad (AdWords API Team)

unread,
Jan 27, 2017, 2:20:29 PM1/27/17
to AdWords API Forum
Hi,

To add an Audience to your AdGroups or Campaigns, you need to add a criterion of type CriterionUserList using AdGroupCriterionService or CampaignCriterionService respectively. You need to pass the ID of your user list in the userListId field. I'm afraid the library doesn't have an example to demonstrate this. The following code snippet adds an Audience to an AdGroup. 

    CriterionUserList userList = new CriterionUserList();
    userList
.setUserListId(userListId);

   
BiddableAdGroupCriterion criterion = new BiddableAdGroupCriterion();
    criterion
.setAdGroupId(adGroupId);
    criterion
.setCriterion(userList);

   
AdGroupCriterionOperation operation = new AdGroupCriterionOperation();
    operation
.setOperand(criterion);
    operation
.setOperator(Operator.ADD);

   
AdGroupCriterionOperation[] operations = new AdGroupCriterionOperation[] {operation};
   
AdGroupCriterionReturnValue result = adGroupCriterionService.mutate(operations);

Regards,
Shwetha, AdWords API Team.

kuppa.j...@aaa-calif.com

unread,
Jan 27, 2017, 5:10:09 PM1/27/17
to AdWords API Forum
Is it possible to remove an Audience to an existing Adgroup/Campaign? Our current process(manual) is if we have an updated Audience list we will upload and add to the Adgroup/Campaign and remove the old one. We would like to replicate that as well.

Shwetha Vastrad (AdWords API Team)

unread,
Jan 30, 2017, 10:34:55 AM1/30/17
to AdWords API Forum
Hi,

Yes, it is possible to remove an audience criterion from your existing Campaigns or AdGroups, using CampaignCriterionService and AdGroupCriterionService respectively. The process is the same as removing other criteria types like keyword, etc., an example of which is provided here

Kuppa.J...@aaa-calif.com

unread,
Mar 15, 2017, 2:48:37 PM3/15/17
to AdWords API Forum
Do you have an example like you posted above for adding a userlist to campaign instead of Adgroup? Going through the Java API is very confusing.

Shwetha Vastrad (AdWords API Team)

unread,
Mar 15, 2017, 3:45:50 PM3/15/17
to AdWords API Forum
Hi,

Please use the code snippet provided below to add a UserList to a campaign.

CriterionUserList userList = new CriterionUserList();
userList
.setUserListId(userListId);

CampaignCriterion criterion = new CampaignCriterion();
criterion
.setCampaignId(campaignId);
criterion
.setCriterion(userList);

CampaignCriterionOperation operation = new CampaignCriterionOperation();
operation
.setOperand(criterion);
operation
.setOperator(Operator.ADD);

CampaignCriterionOperation[] operations = new CampaignCriterionOperation[] {operation};
CampaignCriterionReturnValue result = campaignCriterionService.mutate(operations);

You can also set other options when you add the CampaignCriterion

Kuppa.J...@aaa-calif.com

unread,
Mar 15, 2017, 3:53:27 PM3/15/17
to AdWords API Forum
Here is my code ( i just barely modified it) - 
    //Campaign operation
   
CampaignCriterionServiceInterface  campaignCriterionService  =
            adWordsServices
.get(session, CampaignCriterionServiceInterface.class);
   
   
long campId = Long.parseLong(campaignId);
   
   
CriterionUserList userList_Camp = new CriterionUserList();
    userList_Camp
.setUserListId(userListId);



   
CampaignCriterion criterion = new CampaignCriterion();

    criterion
.setCampaignId(campId);
    criterion
.setCriterion(userList_Camp);


   
CampaignCriterionOperation operation_camp = new CampaignCriterionOperation();
    operation
.setOperand(criterion);
    operation
.setOperator(Operator.ADD);


   
CampaignCriterionOperation[] operations = new CampaignCriterionOperation[] {operation_camp};
   
CampaignCriterionReturnValue result_camp = campaignCriterionService.mutate(operations);


However I am getting the error -
The method setCriterion(Criterion) in the type CampaignCriterion is not applicable for the arguments (CriterionUserList)
The method setOperand(UserList) in the type UserListOperation is not applicable for the arguments (CampaignCriterion)

I can't seem to pass the userList to criterion

Shwetha Vastrad (AdWords API Team)

unread,
Mar 15, 2017, 4:46:13 PM3/15/17
to AdWords API Forum
Hi, 

Could you provide the version of the client library and API you are using? Also, UserListOperation is applicable for AdwordsUserListService, not CampaignCriterionService. Could you send over the complete code so I can take a look?

Thanks,
Shwetha, AdWords API Team.
Message has been deleted
Message has been deleted
Message has been deleted

Kuppa.J...@aaa-calif.com

unread,
Mar 15, 2017, 5:05:24 PM3/15/17
to AdWords API Forum
The purpose of the script is to read from a table that is updated on a weekly/monthly bases and create groupings of hashed Emails based on unique Clientid/Campaigns then upload the Grouped emails to the clientID then assign it to the proper campaignIds. Im somewhat new to java so please forgive me(there is alot code that is commented)


I have been able to get the uploading of the list to work however the last part adding to campaignid is whats been difficult. 

Shwetha Vastrad (AdWords API Team)

unread,
Mar 16, 2017, 10:27:50 AM3/16/17
to AdWords API Forum
Hi, 

Thank you for sending over the complete Java code. I took a look and saw a couple of errors:
  1. Change the import here to this one instead: import com.google.api.ads.adwords.axis.v201609.cm.CampaignCriterion;
  2. Change the variable "operation" here (which is an instance of UserListOperation) to "operation_camp" (which is an instance of CampaignCriterionOperation). 
Please try this out and let me know if it works. 
Message has been deleted
Message has been deleted

Kuppa.J...@aaa-calif.com

unread,
Mar 21, 2017, 11:37:34 AM3/21/17
to AdWords API Forum
Hi Shwetha,

Thanks for all your help in modifying my code to work.However I was wondering if the size or time it takes to do my entire upload is a problem? When I was testing i was using a small sample set however using my entire CRM email list(Using customized table) I create groups of email uploads based on combination of CLientID/CampaignID then upload to CLientID then CampaignID, however each grouping is 3.6 million rows(Total of about 19 groupings 3.6 mill emails each). And from the API documentation I read you can only have 1mil max UserList size, so I chunk it with groupings of 250k or 500k emails. However when I run my script I get a myriad of errors., It will go through a portion of them and will give me a XML_STREAM_EXC error or null on the System.out.println in this code 


   
for (UserList userListResult : mutateMembersResult.getUserLists()) {
     
System.out.printf("%d email addresses were uploaded to user list with name '%s' and ID %d "
         
+ "and are scheduled for review.%n",
          hashedEmails
.size(), userListResult.getName(), userListResult.getId());
   
}    
    cnt
+= 1;
It seems like it times out or the size/overall upload amount is to much. I also have received SSL Exception as well saying socket peer reset.

Any Ideas ?

Here is my source code - 

Shwetha Vastrad (AdWords API Team)

unread,
Mar 21, 2017, 2:24:08 PM3/21/17
to AdWords API Forum
Hi, 

Could you enable logging and send over the SOAP request and response logs generated, so I can check if you are getting a successful response for the MutateMembersOperation? If the MutateMembersOperation resulted in an error/exception, you wouldn't be able to print out the details of the result. Once I have the logs, I'll be able to further troubleshoot to find the source of the issue. Please use Reply privately to author when responding. 

Kuppa.J...@aaa-calif.com

unread,
Mar 22, 2017, 11:14:11 AM3/22/17
to AdWords API Forum
Hi Shwetha did you receive my private message? I sent 2(I think) however I don't see were I can verify that it went through to you.

Nadine Sundquist (AdWords API Team)

unread,
Mar 22, 2017, 5:35:00 PM3/22/17
to AdWords API Forum
Greetings!

Yes, we got it. I'm taking a look at it now. I'll get back to you soon.

Best,
Nadine, AdWords API Team

pra...@lifecycledigitalmarketing.com

unread,
Nov 2, 2017, 6:00:28 AM11/2/17
to AdWords API Forum
Hey is there a link to a python version of this snippet?

Nadine Sundquist (AdWords API Team)

unread,
Nov 2, 2017, 10:03:42 AM11/2/17
to AdWords API Forum
Hello,

In the future, could you please start a new thread with a link over to the thread that you're referencing? This really helps both our forum users and us. Since this is such a short question, I'll just answer it here.

We don't have an EXACT example for adding a user list as ad group criterion, but we do have a very close one. If you look at the example in Python for Add demographic targeting criteria to an ad group, you can change out the gender criterion for a user list criterion instead. The rest of the code would stay the same.

Best,
Nadine, AdWords API Team
Reply all
Reply to author
Forward
0 new messages