[AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[0].operand]

321 views
Skip to first unread message

하진호

unread,
Feb 15, 2017, 6:26:34 AM2/15/17
to AdWords API Forum
Hi, there

I tried to add age and gender in an adgroup, but i get following error message: [AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[0].operand].
I want to set both gender and age in an adgroup at once.

my source example : 

[
  {
    "adGroupId": 38658396945,
    "ageIds": [
      503001
    ],
    "genderIds": [
      11
    ]
  }
]


demographicList.stream().forEach(i -> {

i.getGenderIds().stream().forEach(genderId -> {
Gender gender = new Gender();
gender.setId(genderId);
BiddableAdGroupCriterion genderBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
genderBiddableAdGroupCriterion.setAdGroupId(i.getAdGroupId());
genderBiddableAdGroupCriterion.setCriterion(gender);

AdGroupCriterionOperation genderAdGroupCriterionOperation = new AdGroupCriterionOperation();
genderAdGroupCriterionOperation.setOperand(genderBiddableAdGroupCriterion);
genderAdGroupCriterionOperation.setOperator(Operator.ADD);

criterionOperationList.add(genderAdGroupCriterionOperation);
});

i.getAgeIds().stream().forEach(ageId -> {
AgeRange ageRange = new AgeRange();
ageRange.setId(ageId);
BiddableAdGroupCriterion ageBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
ageBiddableAdGroupCriterion.setAdGroupId(i.getAdGroupId());
ageBiddableAdGroupCriterion.setCriterion(ageRange);

AdGroupCriterionOperation adGroupCriterionOperation = new AdGroupCriterionOperation();
adGroupCriterionOperation.setOperand(ageBiddableAdGroupCriterion);
adGroupCriterionOperation.setOperator(Operator.ADD);

criterionOperationList.add(adGroupCriterionOperation);
});
});

AdGroupCriterionReturnValue result = adGroupCriterionService
.mutate(criterionOperationList.toArray(new AdGroupCriterionOperation[criterionOperationList.size()]));

Thank you

AdWordsApiUser

unread,
Feb 15, 2017, 9:56:02 AM2/15/17
to AdWords API Forum
Maybe you've excluded one of them explicitly using "NegativeAdGroupCriterion" or at the campaign level? This error only shows up in such a case.

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Feb 15, 2017, 1:58:02 PM2/15/17
to adwor...@googlegroups.com
Hi, 

As pointed out in the earlier post, conflicting criterion setting is causing this error. You could try the AdGroupCriterionService.get() on that AdGroup and check for the criterionUse to see if the targeting that you are trying to set is already set as negative criterion. If so, the workaround would be to remove that and add the right targeting. 

You could check our sample in Java which adds both biddable and negative criterion and try the same in PHP. 

Please let me know if you have any additional questions. 

Thanks,
Sreelakshmi, AdWords API Team
Message has been deleted

하진호

unread,
Feb 16, 2017, 3:41:27 AM2/16/17
to AdWords API Forum
Hi,

Thank you for your answer.
I looked into your sample, and it seemed the process was too complicated.
According to your suggestion, you must add 1 gender and then remove 1 age range or the other way around in order to set for instance, Male 18-24(10, 503001). 
Based on this process, if I want to target Male with 18-24 and 25-34(gender id: 10/ ageRange: 503001, 503002), I have to repeat adding and removing each targeting options several times. Am I getting this right? 
Instead of repeating the process of adding and removing targeting options, I want to create an ad group with specific demographic options selected AT ONCE. 
For example, I want to set ageRange id 503001, 503002 and gender id 10 for adgroup at the same time.

If possible, can you give an example of setting Male, 18-24, 25-34? We can’t find any samples we could refer to in this forum especially on demographic targeting for creating campaigns.

Thanks!!

2017년 2월 16일 목요일 오전 3시 58분 2초 UTC+9, Sreelakshmi Sasidharan (AdWords API Team) 님의 말:

Vishal Vinayak (Adwords API Team)

unread,
Feb 16, 2017, 2:52:29 PM2/16/17
to AdWords API Forum
Hi,

I will be providing support in the meantime as Sreelakshmi is currently OOO. To clarify, AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE error is observed when one tries to ADD as well as EXCLUDE a criteria to an ad group at the same time. As an example, if you try to add the gender criteria ID 11 to an ad group and also try to exclude the same criteria (i.e. adding gender criteria ID 11 as a negative criteria) on the ad group, you would receive this error. I would recommend comparing each criteria ID that you are trying to add and exclude to the ad group with the criteria IDs already associated with the ad group. As suggested by Sreelakshmi earlier, you can use AdGroupCriterionService.get to check all criteria that are already defined on the ad group. If need be, please try removing all criteria already defined on the ad group using AdGroupCriterionService.mutate and try adding the criteria again.

To your question, if you plan to targ
et males with the age range 18-24 and 25-34 in a single request, you can use the following code snippet:

    Gender male = new Gender();
    male.setId(10L);
    
    AgeRange a18to24 = new AgeRange();
    a18to24.setId(503001L);
    
    AgeRange a25to34 = new AgeRange();
    a25to34.setId(503002L);
    
    BiddableAdGroupCriterion genderBiddableAdGroupCriterion = new BiddableAdGroupCriterion();
    genderBiddableAdGroupCriterion.setAdGroupId(adGroupId);
    genderBiddableAdGroupCriterion.setCriterion(male);
    
    BiddableAdGroupCriterion a18to24BiddableAdGroupCriterion = new BiddableAdGroupCriterion();
    a18to24BiddableAdGroupCriterion.setAdGroupId(adGroupId);
    a18to24BiddableAdGroupCriterion.setCriterion(a18to24);
    
    BiddableAdGroupCriterion a25to34BiddableAdGroupCriterion = new BiddableAdGroupCriterion();
    a25to34BiddableAdGroupCriterion.setAdGroupId(adGroupId);
    a25to34BiddableAdGroupCriterion.setCriterion(a25to34);
    
    AdGroupCriterionOperation genderAdGroupCriterionOperation = new AdGroupCriterionOperation();
    genderAdGroupCriterionOperation.setOperand(genderBiddableAdGroupCriterion);
    genderAdGroupCriterionOperation.setOperator(Operator.ADD);
    
    AdGroupCriterionOperation a18to24AdGroupCriterionOperation = new AdGroupCriterionOperation();
    a18to24AdGroupCriterionOperation.setOperand(a18to24BiddableAdGroupCriterion);
    a18to24AdGroupCriterionOperation.setOperator(Operator.ADD);
    
    AdGroupCriterionOperation a25to34AdGroupCriterionOperation = new AdGroupCriterionOperation();
    a25to34AdGroupCriterionOperation.setOperand(a25to34BiddableAdGroupCriterion);
    a25to34AdGroupCriterionOperation.setOperator(Operator.ADD);

    AdGroupCriterionReturnValue result =
        adGroupCriterionService.mutate(new AdGroupCriterionOperation[] {
            genderAdGroupCriterionOperation, 
            a18to24AdGroupCriterionOperation,
            a25to34AdGroupCriterionOperation
            });

If you are still facing issues, please revert with the SOAP XML request and response logs for the API call and I would be happy to dig deeper.

Regards,
Vishal, AdWords API Team

하진호

unread,
Feb 16, 2017, 10:06:26 PM2/16/17
to AdWords API Forum
Hi, 

Thank you for your answer.
I used the code you suggested, but received same error:

result xml 


<?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <soapenv:Header>
        <ns1:RequestHeader xmlns:ns1="https://adwords.google.com/api/adwords/cm/v201609" soapenv:mustUnderstand="0">
            <ns1:clientCustomerId>4234257575</ns1:clientCustomerId>
            <ns1:developerToken>REDACTED</ns1:developerToken>
            <ns1:userAgent>unknown (AwApi-Java, AdWords-Axis/2.21.0, Common-Java/2.21.0, Axis/1.4, Java/1.8.0_101, maven)</ns1:userAgent>
            <ns1:validateOnly>false</ns1:validateOnly>
            <ns1:partialFailure>false</ns1:partialFailure>
        </ns1:RequestHeader>
    </soapenv:Header>
    <soapenv:Body>
            <operations>
                <operator>ADD</operator>
                <operand xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201609" xsi:type="ns2:BiddableAdGroupCriterion">
                    <ns2:adGroupId>38658396945</ns2:adGroupId>
                    <ns2:criterion xsi:type="ns2:Gender">
                        <ns2:id>10</ns2:id>
                    </ns2:criterion>
                </operand>
            </operations>
            <operations>
                <operator>ADD</operator>
                <operand xmlns:ns3="https://adwords.google.com/api/adwords/cm/v201609" xsi:type="ns3:BiddableAdGroupCriterion">
                    <ns3:adGroupId>38658396945</ns3:adGroupId>
                    <ns3:criterion xsi:type="ns3:AgeRange">
                        <ns3:id>503001</ns3:id>
                    </ns3:criterion>
                </operand>
            </operations>
            <operations>
                <operator>ADD</operator>
                <operand xmlns:ns4="https://adwords.google.com/api/adwords/cm/v201609" xsi:type="ns4:BiddableAdGroupCriterion">
                    <ns4:adGroupId>38658396945</ns4:adGroupId>
                    <ns4:criterion xsi:type="ns4:AgeRange">
                        <ns4:id>503002</ns4:id>
                    </ns4:criterion>
                </operand>
            </operations>
        </mutate>
    </soapenv:Body>
</soapenv:Envelope>

Exception in thread "main" AxisFault
 faultSubcode: 
 faultString: [AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[1].operand, AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[2].operand]
 faultActor: 
 faultNode: 
 faultDetail: 
{https://adwords.google.com/api/adwords/cm/v201609}ApiExceptionFault:<message>[AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[1].operand, AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[2].operand]</message><ApplicationException.Type>ApiException</ApplicationException.Type><errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AdGroupCriterionError"><fieldPath>operations[1].operand</fieldPath><trigger/><errorString>AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE</errorString><ApiError.Type>AdGroupCriterionError</ApiError.Type><reason>CANNOT_TARGET_AND_EXCLUDE</reason></errors><errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AdGroupCriterionError"><fieldPath>operations[2].operand</fieldPath><trigger/><errorString>AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE</errorString><ApiError.Type>AdGroupCriterionError</ApiError.Type><reason>CANNOT_TARGET_AND_EXCLUDE</reason></errors>

[AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[1].operand, AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[2].operand]
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at java.lang.Class.newInstance(Class.java:442)
at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:104)
at org.apache.axis.encoding.ser.BeanDeserializer.<init>(BeanDeserializer.java:90)
at com.google.api.ads.adwords.axis.v201609.cm.ApiException.getDeserializer(ApiException.java:156)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at org.apache.axis.encoding.ser.BaseDeserializerFactory.getSpecialized(BaseDeserializerFactory.java:154)
at org.apache.axis.encoding.ser.BaseDeserializerFactory.getDeserializerAs(BaseDeserializerFactory.java:84)
at org.apache.axis.encoding.DeserializationContext.getDeserializer(DeserializationContext.java:464)
at org.apache.axis.encoding.DeserializationContext.getDeserializerForType(DeserializationContext.java:547)
at org.apache.axis.message.SOAPFaultDetailsBuilder.onStartChild(SOAPFaultDetailsBuilder.java:157)
at org.apache.axis.encoding.DeserializationContext.startElement(DeserializationContext.java:1035)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.startElement(AbstractSAXParser.java:509)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.scanStartElement(XMLNSDocumentScannerImpl.java:380)[17 2월 2017 10:17:24,260-soapXmlLogger:WARN:main] SOAP Response:
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
    <soap:Header>
        <ResponseHeader xmlns="https://adwords.google.com/api/adwords/cm/v201609">
            <requestId>000548afad133c880a621502c90b16d5</requestId>
            <serviceName>AdGroupCriterionService</serviceName>
            <methodName>mutate</methodName>
            <operations>3</operations>
            <responseTime>338</responseTime>
        </ResponseHeader>
    </soap:Header>
    <soap:Body>
        <soap:Fault>
            <faultcode>soap:Server</faultcode>
            <faultstring>[AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[1].operand, AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[2].operand]</faultstring>
            <detail>
                <ApiExceptionFault xmlns="https://adwords.google.com/api/adwords/cm/v201609">
                    <message>[AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[1].operand, AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE @ operations[2].operand]</message>
                    <ApplicationException.Type>ApiException</ApplicationException.Type>
                    <errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AdGroupCriterionError">
                        <fieldPath>operations[1].operand</fieldPath>
                        <trigger/>
                        <errorString>AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE</errorString>
                        <ApiError.Type>AdGroupCriterionError</ApiError.Type>
                        <reason>CANNOT_TARGET_AND_EXCLUDE</reason>
                    </errors>
                    <errors xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="AdGroupCriterionError">
                        <fieldPath>operations[2].operand</fieldPath>
                        <trigger/>
                        <errorString>AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE</errorString>
                        <ApiError.Type>AdGroupCriterionError</ApiError.Type>
                        <reason>CANNOT_TARGET_AND_EXCLUDE</reason>
                    </errors>
                </ApiExceptionFault>
            </detail>
        </soap:Fault>
    </soap:Body>
</soap:Envelope>


at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl$FragmentContentDriver.next(XMLDocumentFragmentScannerImpl.java:2781)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentScannerImpl.next(XMLDocumentScannerImpl.java:606)
at com.sun.org.apache.xerces.internal.impl.XMLNSDocumentScannerImpl.next(XMLNSDocumentScannerImpl.java:118)
at com.sun.org.apache.xerces.internal.impl.XMLDocumentFragmentScannerImpl.scanDocument(XMLDocumentFragmentScannerImpl.java:504)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:848)
at com.sun.org.apache.xerces.internal.parsers.XML11Configuration.parse(XML11Configuration.java:777)
at com.sun.org.apache.xerces.internal.parsers.XMLParser.parse(XMLParser.java:141)
at com.sun.org.apache.xerces.internal.parsers.AbstractSAXParser.parse(AbstractSAXParser.java:1213)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl$JAXPSAXParser.parse(SAXParserImpl.java:643)
at com.sun.org.apache.xerces.internal.jaxp.SAXParserImpl.parse(SAXParserImpl.java:327)
at org.apache.axis.encoding.DeserializationContext.parse(DeserializationContext.java:227)
at org.apache.axis.SOAPPart.getAsSOAPEnvelope(SOAPPart.java:696)
at org.apache.axis.Message.getSOAPEnvelope(Message.java:435)
at org.apache.axis.handlers.soap.MustUnderstandChecker.invoke(MustUnderstandChecker.java:62)
at org.apache.axis.client.AxisClient.invoke(AxisClient.java:206)
at org.apache.axis.client.Call.invokeEngine(Call.java:2784)
at org.apache.axis.client.Call.invoke(Call.java:2767)
at org.apache.axis.client.Call.invoke(Call.java:2443)
at org.apache.axis.client.Call.invoke(Call.java:2366)
at org.apache.axis.client.Call.invoke(Call.java:1812)
at com.google.api.ads.adwords.axis.v201609.cm.AdGroupCriterionServiceSoapBindingStub.mutate(AdGroupCriterionServiceSoapBindingStub.java:1693)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.google.api.ads.common.lib.soap.SoapClientHandler.invoke(SoapClientHandler.java:109)
at com.google.api.ads.common.lib.soap.axis.AxisHandler.invokeSoapCall(AxisHandler.java:248)
at com.google.api.ads.common.lib.soap.SoapServiceClient.callSoapClient(SoapServiceClient.java:62)
at com.google.api.ads.common.lib.soap.SoapServiceClient.invoke(SoapServiceClient.java:92)
at com.sun.proxy.$Proxy18.mutate(Unknown Source)
at adwords.axis.v201609.targeting.AddDemographicTargetingCriteria.runExample(AddDemographicTargetingCriteria.java:128)
at adwords.axis.v201609.targeting.AddDemographicTargetingCriteria.main(AddDemographicTargetingCriteria.java:58)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:498)
at com.intellij.rt.execution.application.AppMain.main(AppMain.java:144)

I also got the same error when I tried to add only one criterion.

thank you

2017년 2월 17일 금요일 오전 4시 52분 29초 UTC+9, Vishal Vinayak (Adwords API Team) 님의 말:

Vishal Vinayak (Adwords API Team)

unread,
Feb 17, 2017, 10:08:15 AM2/17/17
to AdWords API Forum
Hi,

Could you please try fetching the criteria that is already defined for the ad group using AdGroupCriterionService.get and send me the console output / SOAP response logs? Please add the fields IdAdGroupIdCriterionUse to the selector (a list of all fields available in the selector can be found here). Please click on Reply privately to author when responding.
Reply all
Reply to author
Forward
0 new messages