I am trying to add a criterion to an ad group for a single shopping product 
item ID. I understand that I need to create a subdivision criterion and an 
"other" criterion, which I will set to Negative. I can't find any samples. 
Here is my attempt, which is giving me 
a LISTING_GROUP_SUBDIVISION_REQUIRES_OTHERS_CASE error:


-- 
-- 
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/adwords-api/5c55067d-eb9b-4eda-9d9d-305aaf97edc5n%40googlegroups.com.
        public void addListingGroupCriterion(String adGroupResourceName, String 
itemId) {
                List<AdGroupCriterionOperation> operations = new ArrayList<>();
                ListingGroupInfo subdivisionListingGroupInfo = 
ListingGroupInfo.newBuilder()
                                
.setType(ListingGroupTypeEnum.ListingGroupType.SUBDIVISION)
                                .build();
                AdGroupCriterion subdivisionCriterion = 
AdGroupCriterion.newBuilder()
                                .setAdGroup(adGroupResourceName)
                                .setListingGroup(subdivisionListingGroupInfo)
                                .setCriterionId(-1L)
                                .build();

                ProductItemIdInfo othersProductItemId = 
ProductItemIdInfo.newBuilder()
                                .build();
                ListingDimensionInfo othersListingDimensionInfo = 
ListingDimensionInfo.newBuilder()
                                .setProductItemId(othersProductItemId)
                                .setProductType(ProductTypeInfo.newBuilder())
                                .build();
                ListingGroupInfo othersListingGroupInfo = 
ListingGroupInfo.newBuilder()
                                
.setType(ListingGroupTypeEnum.ListingGroupType.UNIT)
                                .setCaseValue(othersListingDimensionInfo)
                                
.setParentAdGroupCriterion(subdivisionCriterion.getResourceName())
                                .build();
                AdGroupCriterion othersCriterion = AdGroupCriterion.newBuilder()
                                .setAdGroup(adGroupResourceName)
                                .setListingGroup(othersListingGroupInfo)
                                .setNegative(true)
                                .build();

                ProductItemIdInfo productItemIdInfo = 
ProductItemIdInfo.newBuilder().setValue(itemId).build();
                ListingDimensionInfo productListingDimensionInfo = 
ListingDimensionInfo.newBuilder()
                                .setProductItemId(productItemIdInfo)
                                .build();
                ListingGroupInfo productListingGroupInfo = 
ListingGroupInfo.newBuilder()
                                
.setType(ListingGroupTypeEnum.ListingGroupType.UNIT)
                                .setCaseValue(productListingDimensionInfo)
                                
.setParentAdGroupCriterion(subdivisionCriterion.getResourceName())
                                .build();
                AdGroupCriterion productCriterion = 
AdGroupCriterion.newBuilder()
                                .setAdGroup(adGroupResourceName)
                                
.setStatus(AdGroupCriterionStatusEnum.AdGroupCriterionStatus.ENABLED)
                                .setListingGroup(productListingGroupInfo)
                                .setCpcBidMicros(1000000L)
                                .build();
                
operations.add(AdGroupCriterionOperation.newBuilder().setCreate(subdivisionCriterion).build());
                
operations.add(AdGroupCriterionOperation.newBuilder().setCreate(othersCriterion).build());
                
operations.add(AdGroupCriterionOperation.newBuilder().setCreate(productCriterion).build());
                try (AdGroupCriterionServiceClient agcServiceClient =
                                     
googleAdsClient.getLatestVersion().createAdGroupCriterionServiceClient()) {
                        agcServiceClient.mutateAdGroupCriteria(customerId, 
operations);
                }
        }

Reply via email to