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:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"> <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> <mutate xmlns="https://adwords.google.com/api/adwords/cm/v201609"> <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 faultCode: {http://schemas.xmlsoap.org/soap/envelope/}Server 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) 님의 말: > > Hi, > > I will be providing support in the meantime as Sreelakshmi is currently > OOO. To clarify, AdGroupCriterionError.CANNOT_TARGET_AND_EXCLUDE > <https://developers.google.com/adwords/api/docs/reference/v201605/AdGroupCriterionService.AdGroupCriterionError.Reason> > 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 > <https://developers.google.com/adwords/api/docs/reference/v201609/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 > <https://developers.google.com/adwords/api/docs/reference/v201609/AdGroupCriterionService#mutate> > and > try adding the criteria again. > > To your question, if you plan to target 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 > -- -- =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ Also find us on our blog and Google+: https://googleadsdeveloper.blogspot.com/ https://plus.google.com/+GoogleAdsDevelopers/posts =~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~ You received this message because you are subscribed to the Google Groups "AdWords API Forum" group. To post to this group, send email to adwords-api@googlegroups.com To unsubscribe from this group, send email to adwords-api+unsubscr...@googlegroups.com 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 Forum" group. To unsubscribe from this group and stop receiving emails from it, send an email to adwords-api+unsubscr...@googlegroups.com. Visit this group at https://groups.google.com/group/adwords-api. To view this discussion on the web visit https://groups.google.com/d/msgid/adwords-api/0e3f788e-f2a0-4eaa-a39c-af0792022784%40googlegroups.com. For more options, visit https://groups.google.com/d/optout.