Account extensions: Add new extensions

44 views
Skip to first unread message

rafa....@rocketroi.com

unread,
May 11, 2017, 11:11:14 AM5/11/17
to AdWords API Forum
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>





Shwetha Vastrad (AdWords API Team)

unread,
May 11, 2017, 2:02:10 PM5/11/17
to AdWords API Forum
Hi Rafa, 

Could you provide the complete SOAP request log for these operations as well? To prevent the new settings from overwriting the old settings, you need to send back all feed items, even if you're modifying just one item. I see that you are adding the REMOVE operations after the ADD operations. Could you first make a request to remove the Ad extensions and then perform the ADD operations in the next request and see if it works? Please use Reply privately to author when responding.

Thanks,
Shwetha, AdWords API Team.
Reply all
Reply to author
Forward
0 new messages