How do I set custom date range when downloading reports using adwords API PHP client library.

2,907 views
Skip to first unread message

jaison....@gmail.com

unread,
Nov 29, 2013, 8:37:07 AM11/29/13
to adwor...@googlegroups.com
I am using adwords PHP client library for my application. I want to to download reports for a custom date range and do not know the right parameters used to set the dates.

Following is the code I'm currently using:


$reportFileName = DS . 'AdPerformanceReport_dated.csv';
$reportType = 'AD_PERFORMANCE_REPORT';
$filePath = dirname(__FILE__) . $reportFileName;
$user = new AdWordsUser();

$user->LogAll();
$user->SetClientCustomerId($adwordClientId);
$user->LoadService('ReportDefinitionService', ADWORDS_VERSION);

$selector = new Selector();
$selector->fields = $reportFields[$reportType];

// Create report definition.
$reportDefinition                                      = new ReportDefinition();
$reportDefinition->selector                        = $selector;
$reportDefinition->reportName                   = 'Ad performance report';
$reportDefinition->dateRangeType             = 'CUSTOM_DATE';
$reportDefinition->reportType                    = $reportType;
$reportDefinition->downloadFormat           = 'CSV';
$reportDefinition->includeZeroImpressions = FALSE;

$options = array('version' => ADWORDS_VERSION);

// Download report.
ReportUtils::DownloadReport($reportDefinition, $filePath, $user, $options);


I hope someone can tell me what are the right parameters to set dates.

Josh Radcliff (AdWords API Team)

unread,
Dec 2, 2013, 3:00:10 PM12/2/13
to adwor...@googlegroups.com
Hi,

You can achieve this by setting the dateRange attribute of your selector to a DateRange with the desired min and max dates.

Cheers,
Josh, AdWords API Team

jaison....@gmail.com

unread,
Dec 3, 2013, 1:54:52 AM12/3/13
to adwor...@googlegroups.com
Thanks Josh. Setting the dateRange solved the issue.

SUBIN P VASU

unread,
Feb 26, 2017, 11:27:13 PM2/26/17
to AdWords API Forum
What is the maximum possible date range? ie. Can I download the last five years reprts uing API?

SUBIN P VASU

unread,
Feb 26, 2017, 11:40:07 PM2/26/17
to AdWords API Forum
What is the maximum possible date range? ie. Can I download the last five years reports using API?

Josh Radcliff (AdWords API Team)

unread,
Feb 27, 2017, 8:35:40 AM2/27/17
to AdWords API Forum
Hi,

You can use the date range of ALL_TIME to request all available dates.


Thanks,
Josh, AdWords API Team
Reply all
Reply to author
Forward
0 new messages