Replace IP Exclusion List (PHP)

55 views
Skip to first unread message

Jeff C

unread,
Dec 5, 2017, 2:02:11 AM12/5/17
to AdWords API Forum
Does anyone know where there is example code for replacing the entire IP Exclusion list for a campaign with a new list?

Vincent Racaza (AdWords API Team)

unread,
Dec 5, 2017, 3:35:22 AM12/5/17
to AdWords API Forum
Hi Jeff,

Currently, we do not have a specific PHP example that would replace an IP Exclusion list from a campaign. However, since you will be deleting the entire existing IP_BLOCK criteria with a new set of IP_BLOCK criteria, then you can use the CampaignCriterionService.get() filtering by CriteriaType = IP_BLOCK and the specific campaign ID to get the list of the criterion. 

You can then store the list of criterion into an array, and then use them as an operand in per CampaignCriterionOperation for the REMOVE operator. For your new IP_BLOCK criterion, you can create a new set of CampaignCriterionOperation with operator = ADD. Please see below for a sample SOAP request snippet on which you can pattern for your PHP code:

<soapenv:Body>
       
<mutate xmlns="https://adwords.google.com/api/adwords/cm/v201710">
           
<operations>
               
<operator>REMOVE</operator>
               
<operand xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201710" xsi:type="ns2:NegativeCampaignCriterion">
                   
<ns2:campaignId>XXXXXXXXXXXXXXX</ns2:campaignId>
                   
<ns2:isNegative>true</ns2:isNegative>
                   
<ns2:criterion xsi:type="ns2:IpBlock">
                       
<ns2:id>XXXXXXXXXXXX</ns2:id>
                       
<ns2:type>IP_BLOCK</ns2:type>
                       
<ns2:Criterion.Type>IpBlock</ns2:Criterion.Type>
                       
<ns2:ipAddress>XXX.X.X.XXX/XX</ns2:ipAddress>
                   
</ns2:criterion>
                   
<ns2:CampaignCriterion.Type>NegativeCampaignCriterion</ns2:CampaignCriterion.Type>
               
</operand>
           
</operations>
           
<operations>
               
<operator>ADD</operator>
               
<operand xmlns:ns3="https://adwords.google.com/api/adwords/cm/v201710" xsi:type="ns3:NegativeCampaignCriterion">
                   
<ns3:campaignId>XXXXXXXXXXXXXXXX</ns3:campaignId>
                   
<ns3:criterion xsi:type="ns3:IpBlock">
                       
<ns3:ipAddress>XX.X.X.XXX/XX</ns3:ipAddress>
                   
</ns3:criterion>
               
</operand>
           
</operations>
       
</mutate>
</soapenv:Body>

Let me know if you have further clarifications.

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