So I'm using ruby client library. Version of gem 'google-ads-googleads' is 21.0.0 and Google Ads API version is 13. After initialising client with my credentials, I try to query one of the Google Ads Get Account Hierarchy endpoint, I get Error message:

<Google::Ads::GoogleAds::V13::Errors::GoogleAdsFailure: errors: [<Google::Ads::GoogleAds::V13::Errors::GoogleAdsError: error_code: <Google::Ads::GoogleAds::V13::Errors::ErrorCode: query_error: :UNEXPECTED_END_OF_QUERY>, message: "Error in query: unexpected end of query.">], request_id: "koqtfsaS6CTB0FxlCHucKg">

client = Google::Ads::GoogleAds::GoogleAdsClient.new do |config|       config.client_id = client_id       config.client_secret = client_secret       config.refresh_token = access_token       config.developer_token = developer_token end google_ads_service = client.service.google_ads query = <<~QUERY       SELECT         customer_client.client_customer,         customer_client.level,         customer_client.manager,         customer_client.descriptive_name,         customer_client.currency_code,         customer_client.time_zone,         customer_client.id       FROM customer_client       WHERE customer_client.level <= 1     QUERY begin    request = google_ads_service.search_stream do |search|         search.customer_id = '8148704352'         search.query = query         search.page_size = 100     end     request.each do |response|                           response.results.each do |row|            puts row        end     end rescue Google::Ads::GoogleAds::Errors::GoogleAdsError => e     puts "Error message: #{e.failure}" end 

I tried

query = <<~SQL   SELECT     customer_client.client_customer,     customer_client.level,     customer_client.manager,     customer_client.descriptive_name,     customer_client.currency_code,     customer_client.time_zone,     customer_client.id   FROM customer_client   WHERE customer_client.level <= 1 SQL 

I also tried enclosing query in single quotes like query_with_single_quotes = ''' + query + ''' but the error doesn't go away.

Tag:google-ads-api, ruby-on-rails

Only one comment.

  1. valduane

    Try to use SQL.squish instead of query:

    query = <<~SQL.squish SELECT customer_client.client_customer, customer_client.level, customer_client.manager, customer_client.descriptive_name, customer_client.currency_code, customer_client.time_zone, customer_client.id FROM customer_client WHERE customer_client.level <= 1 SQL

    By the way, this project has active record? If it has, you can just write something like this:

    CustomerClient.where('level <= 1') .pluck(:id, :client_customer, :level, :manager, :descriptive_name, :currency_code, :time_zone)

Add a new comment.