I'm trying to pull a pretty basic report from DFP via API and the PHP library provided by Google, https://github.com/googleads/googleads-php-lib/. I've tried both creating the query in the UI and fetching that ReportQuery from the API and running it (per https://developers.google.com/doubleclick-publishers/docs/reporting#retrieving_a_saved_reportquery) as well as creating an ad hoc query. All create the request okay, which seems to imply that the query validates okay. Other API requests I've tested work fine, including fetching a list of line items etc.
The pertinent code is as follows:
$statementBuilder = (new StatementBuilder())
->where('AD_UNIT_NAME like \'prebid_\'');
# Create report query.
$reportQuery = new ReportQuery();
$reportQuery->setDimensions([
Dimension::AD_UNIT_NAME,
Dimension::CUSTOM_CRITERIA,
Dimension::DATE
]);
$reportQuery->setColumns([
Column::TOTAL_INVENTORY_LEVEL_IMPRESSIONS,
Column::TOTAL_INVENTORY_LEVEL_WITHOUT_CPD_AVERAGE_ECPM
]);
$reportQuery->setStatement($statementBuilder->toStatement());
$reportQuery->setAdUnitView(ReportQueryAdUnitView::TOP_LEVEL);
$reportQuery->setDateRangeType(DateRangeType::YESTERDAY);
# Create report job.
$reportJob = new ReportJob();
$reportJob->setReportQuery($reportQuery);
# Run report job.
$reportJob = $reportService->runReportJob($reportJob);
# Create report downloader.
$reportDownloader = new ReportDownloader($reportService, $reportJob->getId(), POLL_TIME_SECONDS);
# Wait for the report to be ready.
$reportDownloader->waitForReportToFinish();
# Change to your file location.
$filePath = sprintf('%s.csv.gz', tempnam(sys_get_temp_dir(),
'delivery-report-'));
printf("Downloading report to %s ...\n", $filePath);
# Download the report.
$reportDownloader->downloadReport('CSV_DUMP', $filePath);
Here's the error message I get from the API:
PHP Fatal error: Uncaught exception 'UnexpectedValueException' with message 'Cannot download report 1834923393 because it has a status of FAILED.' in ~/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Dfp/Util/v201611/ReportDownloader.php:146
Stack trace:
#0 ~/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Dfp/Util/v201611/ReportDownloader.php(116): Google\AdsApi\Dfp\Util\v201611\ReportDownloader->getDownloadUrl('CSV_DUMP')
#1 ~/test/dfp/get_prebid_unit_data.php(85): Google\AdsApi\Dfp\Util\v201611\ReportDownloader->downloadReport('CSV_DUMP', '/tmp/delivery-r...')
#2 {main}
thrown in ~/test/vendor/googleads/googleads-php-lib/src/Google/AdsApi/Dfp/Util/v201611/ReportDownloader.php on line 146
I have done similar kind of report using below code. Hope it would be helpful for you.