Not receiving some data fields from Google Ads API Beta v2 Search Queries

449 views
Skip to first unread message

Dylan McBurnett

unread,
Sep 17, 2019, 7:06:47 PM9/17/19
to AdWords API and Google Ads API Forum
Hi,

I'm trying to use the Google Ads Beta API Interactive Search Query Builder with the google-ads-python Github repo to gather information for a dashboard. I'm successfully able to retrieve about half of the information I'm looking for, but some of the queries created by the Builder either return no data or indicate an error with the query that I do not understand.

Code I'm using to run the queries:

from __future__ import absolute_import
import argparse
import six
import sys
import google.ads.google_ads.client
_DEFAULT_PAGE_SIZE = 1000
def main(client, customer_id, page_size):
ga_service = client.get_service('GoogleAdsService', version='v2')

# ********************NOTES*********************
# query1 successfully returns data for: campaign.id, campaign.name, segments.ad_network_type, segments.device, campaign.shopping_setting.campaign_priority
# query1 returns no data for bidding_strategy.type, language_code, custom_parameters
query1 = ( 'SELECT campaign.id, campaign.name, '
'segments.ad_network_type, segments.device, '
'bidding_strategy.type, campaign.dynamic_search_ads_setting.language_code, '
'campaign.shopping_setting.campaign_priority, '
'campaign_budget.type, campaign.url_custom_parameters '
'FROM campaign '
'LIMIT 20')
# query2 returns no data for bidding_strategy.type or name
query2 = ( 'SELECT bidding_strategy.type, bidding_strategy.name, '
'FROM bidding_strategy '
'LIMIT 20')

results = ga_service.search(customer_id, query=query#NUMBER#, page_size=page_size)
print str(results)
try:
for row in results:
print '******** ROW DATA'
print str(row)
print('Campaign with ID %d and name/Priority "%s" was found.'
% (row.campaign.id.value, row.campaign.shopping_setting.campaign_priority))
# % (row.campaign.id.value, row.campaign.name.value))
except google.ads.google_ads.errors.GoogleAdsException as ex:
print 'Why are you so wrong?'
print('Request with ID "%s" failed with status "%s" and includes the '
'following errors:' % (ex.request_id, ex.error.code().name))
for error in ex.failure.errors:
print('\tError with message "%s".' % error.message)
if error.location:
for field_path_element in error.location.field_path_elements:
print('\t\tOn field: %s' % field_path_element.field_name)
sys.exit(1)
if __name__ == '__main__':
# GoogleAdsClient will read the google-ads.yaml configuration file in the
# home directory if none is specified.
google_ads_client = (google.ads.google_ads.client.GoogleAdsClient
.load_from_storage())
parser = argparse.ArgumentParser(
description='Lists all campaigns for specified customer.')
# The following argument(s) should be provided to run the example.
parser.add_argument('-c', '--customer_id', type=six.text_type,
required=True, help='The Google Ads customer ID.')
args = parser.parse_args()
main(google_ads_client, args.customer_id, _DEFAULT_PAGE_SIZE)



Here's a summary of the values I'm searching for, the query language I provided, and the responses I received.

Fields that don't work in my queries:
- Desired Field : 'query formatting provided by Query Builder'

Bid Strategy Type .. this is query2 in the code above: 'bidding_strategy.type FROM bidding_strategy'
----> returns no data, when requesting 'FROM campaign' response object comes back with other requested data but nothing for Bid Strategy Type
----> returns Invalid Argument Error when requesting 'FROM bidding_strategy' look at 'query2' in code below ..
Terminal Logs for my query2
Dylan-McBurnetts-MacBook-Pro:basic_operations dylanmcburnett$ ./get_dylan_data.py -c 2036267401 <google.api_core.page_iterator.GRPCIterator object at 0x10e526310> hello No handlers could be found for logger "google.ads.google_ads.client" Why are you so wrong? Request with ID "7CjQwf-ivGcDF1ApnrDmTQ" failed with status "INVALID_ARGUMENT" and includes the following errors: Error with message "Error in SELECT clause: invalid field name 'FROM'.".

- Language Code : 'campaign.dynamic_search_ads_setting.language_code FROM campaign'
-----> No data returned

- Location: 'location_view.resource_name FROM location_view'
-----> No data returned

- Active Bid Adjustment: 'campaign_criterion.bid_modifier FROM campaign_criterion'

- Custom Parameters: 'campaign.url_custom_parameters FROM campaign'

Negative Keywords: returns an empty object fro the query below
queryNegKey = ( 'SELECT '
     'keyword_plan_negative_keyword.keyword_plan_campaign, '
'keyword_plan_negative_keyword.match_type, keyword_plan_negative_keyword.resource_name '
'FROM keyword_plan_negative_keyword '
'LIMIT 50' )
-
Fields that do work: queries for the values below all work indicating that my access and permissions are correct as far as I can tell
- Campaign ID: 'campaign.id'
- Campaign Name: 'campaign.name'
- Network : ' segments.ad_network_type'
- Delivery: 'campaign_budget.delivery_method'
- Device: 'segments.device'
- Campaign Priority: 'campaign.shopping_setting.campaign_priority'
- Attribution: 'conversion_action conversion_action.attribution_model_settings.attribution_model'

How can I properly retrieve my missing values listed above?
Please let me know if there's any additional information I can provide.

Google Ads API Forum Advisor Prod

unread,
Sep 18, 2019, 3:40:41 PM9/18/19
to dylan.m...@mightyhive.com, adwor...@googlegroups.com

Hi Dylan,

Thank you for reaching out. Please find my response to your queries below.

  • SELECT bidding_strategy.type, bidding_strategy.name FROM bidding_strategy: The query seems to be correct. If you have the bidding strategy set in your account, this query will list the name and type of bidding strategy in result. Could you please confirm if you have the bidding strategy set in your account and let me know if you are still facing issue?

  • bidding_strategy.type returns no data, when requesting 'FROM campaign' response object comes back with other requested data but nothing for Bid Strategy Type: Please use campaign.bidding_strategy_type instead to query the bidding strategy type for campaigns. Please find below the report query for reference.

'SELECT campaign.id, campaign.name, campaign.bidding_strategy_type FROM campaign'

  • Returns Invalid Argument Error when requesting 'FROM bidding_strategy' look at 'query2' in code below : This seems to be formatting error and not the report query error. Could you please format the query correctly as above and retry running the request call?

  • Language Code : 'SELECT campaign.dynamic_search_ads_setting.language_code FROM campaign': The report query is correct and you should get the targeted language code for your campaign in below format.
    campaign {
      dynamic_search_ads_setting {
        language_code {
          value: "en"
        }
      }re the client customer id and the dow

  • Location: SELECT location_view.resource_name FROM location_view: The report query looks perfect. Could you please confirm if there are locations in the UI for which you are trying to get the details via API? If yes, could you please share the client customer id and the downloaded report file for me to investigate further? 

  • Active Bid Adjustment: 'SELECT campaign_criterion.bid_modifier FROM campaign_criterion': Please make sure you have bid modifier set for the campaign criterion in UI for which you are trying to get the data via API?

  • Custom Parameters: ' SELECT campaign.url_custom_parameters FROM campaign' : Could you please confirm if you have custom parameters set at campaign level in UI? If not, you will get an empty result when running this report query. Please refer to this article to set custom parameters at campaign level. Once you have set these parameters, you will get the response in below format.

campaign {
  url_custom_parameters {
    key {
      value: "index"
    }
    value {
      value: "firstPage"
    }
  }
  • Negative Keywords returns an empty object from the query below: Could you confirm if you have campaign negative keywords added in your account? If not, you could add these keywords using this article. Once the negative keywords are added in your account, the shared query will return the requested information in the below format:
keyword_plan_negative_keyword {
  resource_name: "customers/22XXXXXX76/keywordPlanNegativeKeywords/134XXXX54"
  keyword_plan_campaign {
    value: "customers/22XXXXXX76/keywordPlanCampaigns/1XXXXXX2"
  }
  id {
    value: 13XXXX54
  }
  match_type: BROAD
}
Please use Reply privately to author option while sharing the requested details.

Regards,
Nikisha Patel, Google Ads API Team

ref:_00D1U1174p._5001UHH8G9:ref
Reply all
Reply to author
Forward
0 new messages