Home > database >  Google Ads API Update - v10, ERROR: "unexpected input DURING"
Google Ads API Update - v10, ERROR: "unexpected input DURING"

Time:04-29

Google Ads API recently discontinued an old version - https://ads-developers.googleblog.com/2021/04/upgrade-to-google-ads-api-from-adwords.html.

That being said I am trying to adjust my query to new api standards, and getting the strangest error "unexpected input DURING" -- more detail below. It would seem to be correct per this doc:https://developers.google.com/google-ads/api/docs/samples/get-hotel-ads-performance

Note the use of "DURING" in the example SQL query in the doc above.

Below is my error message and further below is script:

ERROR:

SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428
Request made: ClientCustomerId:, Host: googleads.googleapis.com, Method: /google.ads.googleads.v8.services.GoogleAdsService/SearchStream, RequestId:, IsFault: True, FaultMessage: 

Error in query: unexpected input DURING.

script:

import sys, json, io, gzip, sys, os
from googleads import adwords
import pandas as pd
import numpy as np

def google_ads_extract(client,customer_id, s3_path,fields,report_type,statuses,date_range, download_version, job_name):
  ga_service = client.get_service("GoogleAdsService")
  search_request=client.get_type("SearchGoogleAdsStreamRequest")
  search_request.customer_id = customer_id
  query = f"SELECT {', '.join(str(x) for x in fields)} FROM {str(report_type[0])} WHERE Status IN {*statuses,} DURING {date_range}"
  
  # query = "SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion FROM CRITERIA_PERFORMANCE_REPORT WHERE Status IN ('ENABLED', 'PAUSED') DURING 20220427,20220428"
             
  print(query)
  search_request.query = query
  
  stream = ga_service.search_stream(search_request)
  
  for batch in stream:
    for row in batch.results:
      print(row)      
  return 1

CodePudding user response:

To select a time frame you would use

segments.date BETWEEN '2019-01-01' AND '2019-01-31'

But as you have UTC so you can try, but as i can't test it at the moment, you will better run it with dates like abouve

SELECT Date, AdGroupId, AdGroupName, CampaignId, CampaignName, Impressions, Clicks, Cost, Conversions, ConversionRate, Ctr, AverageCpc, CostPerConversion 
FROM CRITERIA_PERFORMANCE_REPORT 
WHERE Status IN ('ENABLED', 'PAUSED') 
  AND segments.date BETWEEN TIMESTAMP_SECONDS(20220427) AND TIMESTAMP_SECONDS(20220428) 
  • Related