Trying to use custom date range in CAMPAIGN_PERFORMANCE_REPORT with Perl

52 views
Skip to first unread message

Mike Diehl

unread,
Apr 2, 2018, 1:45:10 PM4/2/18
to AdWords API Forum
Hi,

I'm trying to create a CAMPAIGN_PERFORMANCE_REPORT using a custom date range, and I'm coding in perl and NOT using AWQL.

Essentially, I've "borrowed" a lot of code from the first example at: https://developers.google.com/adwords/api/docs/samples/perl/reporting

My program works with a  dateRangeType  => "TODAY".  However, when I try dateRangeType   => "CUSTOM_DATE", I get errors.

I create my selector with code that looks like:

 30     my $selector = Google::Ads::AdWords::Reports::Selector->new({
 31         fields => [
 32             "AccountDescriptiveName",
 33             "Date",
 34             "HourOfDay",
 35             "CampaignId",
 36             "CampaignName",
 37             "AveragePosition",
 38             "Impressions",
 39             "Clicks",
 40             "Cost"
 41         ],
 42         date_range => { "min" => "2018-01-01", "max" => "2018-01-02"},
 43         predicates => [$predicate]});

However, when I run my script, I get:

Unknown field date_range in Google::Ads::AdWords::Reports::Selector.
Valid fields are:
fields, predicates, dateRange, ordering, paging
Structure given:
$VAR1 = {
          'predicates' => [
                            bless( do{\(my $o = 5)}, 'Google::Ads::AdWords::Reports::Predicate' )
                          ],
          'fields' => [
                        'AccountDescriptiveName',
                        'Date',
                        'HourOfDay',
                        'CampaignId',
                        'CampaignName',
                        'AveragePosition',
                        'Impressions',
                        'Clicks',
                        'Cost'
                      ],
          'date_range' => {
                            'min' => '2018-01-01',
                            'max' => '2018-01-02'
                          }
        };
 at ./modules/adwords.pm line 30.


So, what am I doing wrong?

Thanks in advance.

Mike Diehl.

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Apr 2, 2018, 3:41:27 PM4/2/18
to adwor...@googlegroups.com
Hi Mike, 

The "dateRangeType" will have to be set as "CUSTOM_DATE" like the code sample is setting it to LAST_7_DAYS. The min and max dates needs to be set in the dateRange which will need to be set in the selector. dateRange will have to be set just like you set predicate in the selector. Please see the report definition given below for more clarity. 

__rdxml: <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<reportDefinition xmlns:ns2="https://adwords.google.com/api/adwords/cm/v201802">
 
<ns2:selector>
   
<ns2:fields>AccountDescriptiveName</ns2:fields>
    <ns2:fields>Date</
ns2:fields>
   
<ns2:fields>HourOfDay</ns2:fields>
    <ns2:fields>CampaignId</
ns2:fields>
   
<ns2:fields>CampaignName</ns2:fields>
    <ns2:fields>AveragePosition</
ns2:fields>
   
<ns2:fields>Impressions</ns2:fields>
    <ns2:fields>Clicks</
ns2:fields>
   
<ns2:fields>Cost</ns2:fields>
    <ns2:predicates>
      <ns2:field>CampaignId</
ns2:field>
     
<ns2:operator>IN</ns2:operator>
      <ns2:values>*******</
ns2:values>
     
<ns2:values>*******</ns2:values>
   
</ns2:predicates>
    <ns2:dateRange>
      <ns2:min>20180101</
ns2:min>
     
<ns2:max>20180102</ns2:max>
    </
ns2:dateRange>
 
</ns2:selector>
  <ns2:reportName>CampaignPerformanceReport #1522696392597</
ns2:reportName>
 
<ns2:reportType>CAMPAIGN_PERFORMANCE_REPORT</ns2:reportType>
  <ns2:dateRangeType>CUSTOM_DATE</
ns2:dateRangeType>
 
<ns2:downloadFormat>CSV</ns2:downloadFormat>
</
reportDefinition>


Please give this a try and let me know if you are still facing issues. 

Thanks,
Sreelakshmi, AdWords API Team

Mike Diehl

unread,
Apr 3, 2018, 10:50:05 AM4/3/18
to AdWords API Forum
You know, I HONESTLY thought I had done all that you suggested.  I even cited the documentation that I followed.

However, when I went back and just followed the instructions you gave me, and fixed a type-o, it worked.

Thanks for your time.

Mike.

Sreelakshmi Sasidharan (AdWords API Team)

unread,
Apr 3, 2018, 12:50:16 PM4/3/18
to AdWords API Forum
Hi Mike, 

Glad that you were able to resolve the issue and get the report working. 
Reply all
Reply to author
Forward
0 new messages