Passing variables into ReportQueryBuilder - GoogleAdsAPI
I am using GoogleAdsApi - and I have the query below that works great. :)
report_query = (adwords.ReportQueryBuilder() .Select( 'Date','AdGroupId','AdGroupName','CampaignId','CampaignName', 'Impressions','Clicks', 'Cost' ,'Conversions','ConversionRate','Ctr','AverageCpc','CostPerConversion' ) .From('CRITERIA_PERFORMANCE_REPORT') .Where('Status').In('ENABLED', 'PAUSED') .During('20200101,20210331') .Build())
I would like to make this function more dynamic by creating a date variable (I have listed below) and possibly more variables let's say field as well. When I try to create & pass in variables ,it does not work
fields = "'Date','AdGroupId','AdGroupName','CampaignId','CampaignName','Impressions','Clicks','Cost','Conversions','ConversionRate','Ctr','AverageCpc','CostPerConversion'" today = date.today() yesterday = today - timedelta(days = 1) date_filter = f'\'{yesterday.strftime("%Y%m%d")},{today.strftime("%Y%m%d")}\'' report_query = (adwords.ReportQueryBuilder() .Select( fields ) .From('CRITERIA_PERFORMANCE_REPORT') .Where('Status').In('ENABLED', 'PAUSED') .During(date_filter) .Build())
I get the error below:
googleads.errors.AdWordsReportBadRequestError: Type: QueryError.INVALID_DURING_CLAUSE
Even though when I pass in the printed value of my date variable, instead of the date variable into .During, it works. So a little confused.