How to add Users in a Remarketing UserList using Google Ads API?
I'm trying to create a remarketing userList add some users into it using the Java implementation for Google Ads Api.
The custom audience creation part looks fine, I can see it created in the Ads plataform, but looks like the users wasn't included into it.
Print screen: Empty custom audience inside google ads plataform
I'm sending a JsonArray with 2000 user as parameter and hashing it inside this function, and used this samples as reference.
I'm not sure if I misunderstood the documentation or if I'm including the userList in a wrong way or anything like that.
public JsonArray uploadJsonList(String customerId, JsonArray jsonUsers) throws Exception { List<Member> members = new ArrayList<>(); JsonObject hashedObj = new JsonObject(); JsonArray arrayJsonHashed = new JsonArray(); for (JsonValue jsonValue : jsonUsers) { JsonObject obj = jsonValue.asObject(); hashedObj = new JsonObject(); //Getting user data String normalizedEmail = textUtils.toNormalizedString(obj.get("PESSOA_EMAIL1").toString()); String normalizedPhone = textUtils.toNormalizedString(obj.get("PESSOA_CELULAR").toString()); String normalizedId = obj.get("PESSOA_ID").toString(); normalizedId = removeFirstandLast(normalizedId); //Hashing user data hashedObj.add("pessoa_email1", textUtils.toSHA256String(normalizedEmail)); hashedObj.add("pessoa_celular", textUtils.toSHA256String(normalizedPhone)); hashedObj.add("pessoa_id",normalizedId); arrayJsonHashed.add(hashedObj); //Creating a member list Member member = new Member(); member.setHashedEmail(textUtils.toSHA256String(normalizedEmail)); member.setHashedPhoneNumber(textUtils.toSHA256String(normalizedPhone)); members.add(member); } //starting ads services AdWordsServices adWordsServices = new AdWordsServices(); Customer[] customers = getCustomers(adWordsServices, session); session.setClientCustomerId(customerId); AdwordsUserListServiceInterface userListService = adWordsServices.get(session, AdwordsUserListServiceInterface.class); // Create a user list. CrmBasedUserList userList = new CrmBasedUserList(); userList.setName("Test Remarketing Custom Audience - " + System.currentTimeMillis()); userList.setDescription("A list of customers that was readed from big query"); // CRM-based user lists can use a membershipLifeSpan of 10000 to indicate unlimited; otherwise // normal values apply. userList.setMembershipLifeSpan(100L); userList.setUploadKeyType(CustomerMatchUploadKeyType.CONTACT_INFO); // Create operation. UserListOperation operation = new UserListOperation(); operation.setOperand(userList); operation.setOperator(Operator.ADD); // Add user list. UserListReturnValue result = userListService.mutate(new UserListOperation[]{operation}); // Display user list. UserList userListAdded = result.getValue(0); System.out.printf( "User list with name '%s' and ID %d was added.%n", userListAdded.getName(), userListAdded.getId()); // Get user list ID. Long userListId = userListAdded.getId(); // Create operation to add members to the user list based on email addresses. MutateMembersOperation mutateMembersOperation = new MutateMembersOperation(); MutateMembersOperand operand = new MutateMembersOperand(); operand.setUserListId(userListId); operand.setMembersList(members.toArray(new Member[members.size()])); mutateMembersOperation.setOperand(operand); mutateMembersOperation.setOperator(Operator.ADD); // Add members to the user list based on email addresses. MutateMembersReturnValue mutateMembersResult = userListService.mutateMembers(new MutateMembersOperation[]{mutateMembersOperation}); // Display results. // Reminder: it may take several hours for the list to be populated with members. 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", members.size(), userListResult.getName(), userListResult.getId()); } return arrayJsonHashed; }