Google Ads REST API - Block IP Address - Get All Blocked IP addresses

2,753 views
Skip to first unread message

John Tzanidakis

unread,
May 19, 2019, 8:43:33 PM5/19/19
to AdWords API and Google Ads API Forum

Hello, 

I am trying to use the Google Ads API with REST, I have followed all the steps including authentication, getting my developer token, creating test accounts, and am able to make a test api call to get a response with: customers:listAccessibleCustomers and do receive a response for my Account I am authenticated with. 

My question is how can I now do more, such as block ip addresses or get all blocked IPs for a specific account, there seems to be no documentation around the REST API anywhere. The only examples are in the getting started pages with the curl requests but everything else is not clear how to get what I need from the documentation. 

From what I've gathered I believe I need the campaignCriteria and perhaps :mutate, but after that I'm not sure how to continue in building this into an actual request. Any help or direction will be greatly appreciated. 

Thanks!

Google Ads API Forum Advisor Prod

unread,
May 20, 2019, 2:08:58 AM5/20/19
to adwor...@googlegroups.com

Hi John,

Thank you for reaching out. I'm afraid that blocking IP addresses or getting all blocked IP's isn't currently possible with the API. However, to better assist you, could you elaborate what do you need to achieve using the Google Ads API? If you wish to use cURL to interact with the API, you may refer to this guide as to how.

Regards,
Dave
Google Ads API Team



ref:_00D1U1174p._5001UAq6wm:ref

John Tzanidakis

unread,
May 21, 2019, 2:37:27 AM5/21/19
to AdWords API and Google Ads API Forum
Hi Dave, 

Thank you for the response, if blocking ip address and getting blocked ip addresses is not currently possible, then what is the IpBlockInfo resource name used for as it is listed here: https://developers.google.com/google-ads/api/reference/rpc/google.ads.googleads.v1.resources#google.ads.googleads.v1.resources.CampaignCriterion? From what i understand using this, you can block and get a list of ips excluded. 

As per the link to the curl request how to, I am able to get that going and get a response, the issue is its not very clear how to make any other call after that. In the API call structure doc it says: 


If you wanted to call the CampaignBudgetService.MutateCampaignBudgets method with an HTTP POST, you would transform that URL to


/v1/customers/{customer_id}/campaignBudgets:mutate


There isn't much information around how this call goes from CampaignBudgetService.MutateCampaignBudgets to campaignBudgets:mutate inside the url, so how does that apply to every other resource name or method?

To give more information on what I am trying to achieve: I am building an application with a NodeJS backend, that will hopefully be able to get a list of blocked Ip address from  a client's ad campaign to show on a React dashboard, and the ability to block ip addresses from a list that we will be providing for them. 

Thanks

Google Ads API Forum Advisor Prod

unread,
May 21, 2019, 6:13:25 AM5/21/19
to adwor...@googlegroups.com

Hi John,

My apologies as I may have overlooked this. Upon checking with the team, excluding IP addresses is indeed possible using the IpBlockInfo field. As per your other concern, I would need to discuss this with the team. I will provide you updates once available.



Regards,
Dave
Google Ads API Team



ref:_00D1U1174p._5001UAq6wm:ref

Google Ads API Forum Advisor Prod

unread,
May 21, 2019, 8:21:11 AM5/21/19
to adwor...@googlegroups.com
Hello,

The pattern is the same across all mutate requests.

/v{x}/customers/{customer_id}/{resource_name_pluralized}:mutate

You can always fall back on looking at the exact proto definition if there's any doubt. Here's the one for campaign budgets, for example: https://github.com/googleapis/googleapis/blob/master/google/ads/googleads/v1/services/campaign_budget_service.proto#L48

In that same folder on GitHub you'll find the protos for every service, which will be defined similarly and explicitly mention the endpoint for every type of request.

Let me know if you need any more help understanding how to form REST requests with JSON; unfortunately we haven't been able to document this process thoroughly yet.

Regards,
Mike, Google Ads API Team

ref:_00D1U1174p._5001UAq6wm:ref

John Tzanidakis

unread,
May 21, 2019, 2:59:01 PM5/21/19
to AdWords API and Google Ads API Forum
Hey Mike, 

Thank you that link clears up most of my confusion with URL patterns for each request. I am still having trouble forming my request though. The documented example uses a json file for the body, how would the body look for a request like adding IP addresses, and/or fetching all?

I know the URL will look like: /v1/customers/{customer_id=*}/campaignCriteria:mutate. 

Along with the criterion ip_block and update operation. How would the full request look like in this case?(a curl example would be fine) I suppose I would also need an API call to get all the campaigns for their IDs to set the blocked ip addresses to, or do the blocked ip addresses fall under all campaigns?  

Thanks

Google Ads API Forum Advisor Prod

unread,
May 22, 2019, 8:08:53 AM5/22/19
to johnt...@gmail.com, adwor...@googlegroups.com
Hello,

When working with JSON REST and curl, I find it easier myself to actually stick to the protos and build the operations from there. For example, this time I referenced campaign_criterion and criteria to find all the relevant fields. The campaign_criterion shows that I need a campaign that is a string, a status that is an enum, which we can pass as a string, and a criteria. With one_of fields, you refer to the actual name of the inner field when setting it in the JSON. Since the object I'm creating is an IpBlockInfo, I looked up the requisite field for that object in the criteria proto. The end result JSON looks like this:

{
  customer_id: "1234567890",
  operations: [
    {
      create: {
        campaign: "customers/1234567890/campaigns/1234",
        status: "ENABLED",
        ip_block: {
          ip_address: "127.0.0.1"
        }
      }
    }
  ]
}


Obviously you will need to customize the IDs and IP addresses to suit your needs, and you should be able to adapt this general format to any request if you look through the protos for the fields you need.

John Tzanidakis

unread,
May 23, 2019, 5:05:16 AM5/23/19
to AdWords API and Google Ads API Forum

Hi, 

Thank you for that JSON and the links to the protos, it seems to clear up how the body of requests should be formed for each call. But running it against my test account's campaigns I am getting this error returned: 

{
   
"error": {
       
"code": 400,
       
"message": "Request contains an invalid argument.",
       
"status": "INVALID_ARGUMENT",
       
"details": [
           
{
               
"@type": "type.googleapis.com/google.ads.googleads.v1.errors.GoogleAdsFailure",
               
"errors": [
                   
{
                       
"errorCode": {
                           
"criterionError": "CANNOT_ADD_CRITERIA_TYPE"
                       
},
                       
"message": "Criteria type can not be targeted.",
                       
"trigger": {
                           
"stringValue": ""
                       
},
                       
"location": {
                           
"fieldPathElements": [
                               
{
                                   
"fieldName": "operations",
                                   
"index": "0"
                               
},
                               
{
                                   
"fieldName": "create"
                               
},
                               
{
                                   
"fieldName": "ip_block"
                               
}
                           
]
                       
}
                   
}
               
]
           
}
       
]
   
}
}

Any help on what this means and what I am doing wrong?

Thanks


Google Ads API Forum Advisor Prod

unread,
May 23, 2019, 7:55:52 AM5/23/19
to johnt...@gmail.com, adwor...@googlegroups.com
Hello,

The message "Criteria type can not be targeted." means that this criteria type is only supported as a negative criteria. I apologize that I didn't notice that in my initial response and sample JSON. You should be able to modify the JSON body to use a negative criterion instead of a positive one, but let me know if you're having difficulties figuring that out.

John Tzanidakis

unread,
May 23, 2019, 10:19:56 PM5/23/19
to AdWords API and Google Ads API Forum

Hi, 

Thank you for that information, I am now able to add ip addresses with the create operation and remove ip addresses with the remove operation from a campaign. I am also able to query for all campaign criterion that are of type IP_BLOCK to get all those blocked ip addresses. But im not able to return the actual ip address in the criterion with that query. To be clear I am using this api call: 


and my request body includes: 

{
  "query": "SELECT campaign.id, campaign.name, campaign.status, campaign.serving_status, campaign_criterion.criterion_id, campaign_criterion.type FROM campaign_criterion WHERE campaign_criterion.type='IP_BLOCK'"
}

As a result I am getting a list of results with this object inside: 

        {
           
"campaign": {
               
"resourceName": "customers/CUSTOMER_ID/campaigns/CAMPAIGN_ID",
               
"id": "CAMPAIGN_ID",
               
"name": "Display-1",
               
"status": "ENABLED",
               
"servingStatus": "SERVING"
           
},
           
"campaignCriterion": {
               
"resourceName": "customers/CUSTOMER_ID/campaignCriteria/CAMPAIGN_ID~CRITERION_ID",
               
"criterionId": "CRITERION_ID",
               
"type": "IP_BLOCK"
           
}
       
}

What do I need to add to the query to get the actual criterion ip_block object with {ip_address: "127.0.0.1"} inside under campaignCriterion to show up? Ive tried all sorts of things such as campaign_criterion.criterion, campaign_criterion.ip_block, campaign_criterion.criterion.ip_block but none seem to be a valid argument. The only other option here would be to make a request for each criterion by its ID to get all of its remaining details/fields but that would be inefficient. Is it possible to retrieve this information within that query?


Google Ads API Forum Advisor Prod

unread,
May 24, 2019, 7:33:28 AM5/24/19
to johnt...@gmail.com, adwor...@googlegroups.com
Hello,

Glad to hear you're mostly up and running! To get the specific IP address, try using campaign_criterion.ip_block.ip_address.
Reply all
Reply to author
Forward
0 new messages