I'm creating extensions at account level, but the problem is that when I
try to create more than on extension of the same type, the ol one ovewrite
the new one.
I have tried removing the existing extensions, and recreate the removed
ones and the new ones, but I'm getting an *DUPLICATE_ELEMENT* error. I do
the following:
1. Get old extensions and save on an Array (to remove)
2. Add old extensions to the new extensions array
3. remove old extensions
4. add new extensions + old extensions
This is the code that I'm using right now:
static CustomerExtensionSettingReturnValue
addCustomerExtensions(AdWordsSession session, List extensions) {
AdWordsServices adWordsServices = new AdWordsServices()
CustomerExtensionSettingServiceInterface
customerExtensionSettingServiceInterface =
adWordsServices.get(session,
CustomerExtensionSettingServiceInterface.class);
//First, we need to separate the extensions by type
Map lstExtensions = separateExtensions(extensions as List)
CustomerExtensionSettingOperation customerSiteLinkOperation =
createSiteLinkExtensionOperation(lstExtensions.lstSiteLinkExtensions)
CustomerExtensionSettingOperation customerCalloutOperation =
createCalloutExtensionOperation(lstExtensions.lstCalloutExtensions)
CustomerExtensionSettingOperation customerAppOperation =
createAppExtensionOperation(lstExtensions.lstAppExtensions)
// Add the extensions.
List<CustomerExtensionSettingOperation> lstAllExtensions = new
ArrayList<CustomerExtensionSettingOperation>();
if (lstExtensions.lstSiteLinkExtensions){
lstAllExtensions.addAll(customerSiteLinkOperation)
}
if (lstExtensions.lstCalloutExtensions){
lstAllExtensions.addAll(customerCalloutOperation)
}
if (lstExtensions.lstAppExtensions){
lstAllExtensions.addAll(customerAppOperation)
}
// Get existing extensions: remove them and add them again
List<CustomerExtensionSettingOperation> toRemoveExtensionsList =
new ArrayList<CustomerExtensionSettingOperation>();
List<CustomerExtensionSetting> existingExtensionsList =
getExtensions(session, "ALL")
if(existingExtensionsList.size() > 0) {
for (CustomerExtensionSetting customerExtensionSetting in
existingExtensionsList) {
CustomerExtensionSettingOperation operationRemove = new
CustomerExtensionSettingOperation()
operationRemove.operand = customerExtensionSetting
operationRemove.setOperator(Operator.REMOVE)
toRemoveExtensionsList.add(operationRemove)
CustomerExtensionSettingOperation operationAdd = new
CustomerExtensionSettingOperation()
operationAdd.operand = customerExtensionSetting
operationAdd.setOperator(Operator.ADD)
lstAllExtensions.add(operationAdd)
}
customerExtensionSettingServiceInterface.mutate((CustomerExtensionSettingOperation[])
(toRemoveExtensionsList.toArray()));
}
return
customerExtensionSettingServiceInterface.mutate((CustomerExtensionSettingOperation[])
(lstAllExtensions.toArray()));
}
And this is the response from Adwords:
<?xml version="1.0" encoding="UTF-8"?><soap:Envelope
xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/">
<soap:Header>
<ResponseHeader
xmlns="https://adwords.google.com/api/adwords/cm/v201607">
<requestId>00054f40df5092300a3741411c00f843</requestId>
<serviceName>CustomerExtensionSettingService</serviceName>
<methodName>mutate</methodName>
<operations>4</operations>
<responseTime>208</responseTime>
</ResponseHeader>
</soap:Header>
<soap:Body>
<soap:Fault>
<faultcode>soap:Server</faultcode>
<faultstring>[DistinctError.DUPLICATE_ELEMENT @
operations[1]]</faultstring>
<detail>
<ApiExceptionFault
xmlns="https://adwords.google.com/api/adwords/cm/v201607">
<message>[DistinctError.DUPLICATE_ELEMENT @
operations[1]]</message>
<ApplicationException.Type>ApiException</ApplicationException.Type>
<errors
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:type="DistinctError">
<fieldPath>operations[1]</fieldPath>
<trigger/>
<errorString>DistinctError.DUPLICATE_ELEMENT</errorString>
<ApiError.Type>DistinctError</ApiError.Type>
<reason>DUPLICATE_ELEMENT</reason>
</errors>
</ApiExceptionFault>
</detail>
</soap:Fault>
</soap:Body>
</soap:Envelope>
--
--
=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~
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 [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 Forum" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
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/41b54267-0d8f-4164-bc98-0e3125b53f7f%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.