Reputation: 501
I'm trying to block an IP list through Google API v2 but I'm getting the error "Criteria type can not be targeted." on field: operations, on field: create, on field: ip_block. Another doubt that I have, is if I will need to repeat the create operation for each IP on my list or there is a way to put multiple Ip on the same request.
client = (google.ads.google_ads.client.GoogleAdsClient.load_from_storage(path="./google-ads.yaml"))
campaign_criterion_operation = client.get_type('CampaignCriterionOperation', version='v2')
campaign_criterion = campaign_criterion_operation.create
campaign_criterion.campaign.value = campaign_service.campaign_path(customer, campaign)
campaign_criterion.ip_block.ip_address.value = "xxx.xxx.xxx.xxx"
campaign_criterion_response = campaign_criterion_service.mutate_campaign_criteria(customer, [campaign_criterion_operation])
for reponse in campaign_criterion_response.results:
print('Added campaign criterion "%s".' % reponse.resource_name)
Upvotes: 1
Views: 783
Reputation: 356
i think you are getting the error because you haven't set the criterion to negative. Im not using the python library but i am using the PHP one.
This is what mine looks like;
$campaign_criterion = new CampaignCriterion([
'ip_block' => new IpBlockInfo([
'ip_address' => 'IP_ADDRESS_HERE'
]),
'negative' => true, // setting it to negative
'campaign' => ResourceNames::forCampaign('XXXXXXXXXX', 'XXXXXXXXXXXX')
]);
And yes, you have to create a campaign criterion per IP Address you want to block.
Upvotes: 3