The DCM/DFA Reporting and Trafficking API v2.7 is deprecated and will be sunset on November 30th, 2017. All users must migrate to a newer API version by that date.

Download Report Files

The DCM/DFA Reporting and Trafficking API allows you to download report files, which are the result of running a Report Builder report. It also supports providing users direct access to a file via a link.

Depending on the type of download you'd like to perform, you'll use one of the following approaches:

The rest of this guide provides detailed instructions for performing these types of downloads via the Files resource.

Prerequisites

In order to download a file, you'll need a few pieces of information:

  1. The ID of the report to which the file belongs. You can find this by creating a new report, or looking up an existing report.
  2. The ID of the file to download. You can find this by running the report from the previous step, or querying the list of existing files as in the example below:

Java

File target = null;
FileList files;
String nextPageToken = null;

do {
  // Create and execute the files list request.
  files = reporting.reports().files().list(profileId, reportId).setPageToken(nextPageToken)
      .execute();

  for (File file : files.getItems()) {
    if (isTargetFile(file)) {
      target = file;
      break;
    }
  }

  // Update the next page token.
  nextPageToken = files.getNextPageToken();
} while (!files.getItems().isEmpty() && !Strings.isNullOrEmpty(nextPageToken));

Note that the status field of the file resource must be set to REPORT_AVAILABLE to be eligible to download.

Direct download

To perform a direct download, you make an authorized HTTP GET request to the Files service and include the query parameter alt=media. An example request may look like this:

GET https://www.googleapis.com/dfareporting/v2.8/reports/12345/files/12345?alt=media HTTP/1.1
Authorization: Bearer your_auth_token

Be aware that the response you receive will contain a redirect, so your application should ideally be configured to handle this automatically. If you prefer to handle this manually, you can find the redirect URL in the Location header of the response.

Most of the official Google client libraries provide convenience methods for initiating a direct download, as shown in the example below. If you prefer to initiate a download manually, a pre-constructed URL is provided in the apiUrl field of the file resource.

Java

// Initiate a direct download.
HttpResponse fileContents = reporting.reports().files().get(profileId, reportId, fileId)
    .executeMedia();

// Display the file contents.
BufferedReader reader = null;
try {
  reader = new BufferedReader(new InputStreamReader(fileContents.getContent(), Charsets.UTF_8));

  System.out.printf("Displaying contents of file %d.%n%n", fileId);

  String line;
  while ((line = reader.readLine()) != null) {
    System.out.println(line);
  }
} finally {
  fileContents.disconnect();

  if (reader != null) {
    reader.close();
  }
}

Resumable downloads

When downloading large report files, it’s possible for the download to fail partway through. To make it easier to recover and resume a failed download, the file service supports partial download functionality.

Partial download involves requesting specific portions of a file, allowing you to break large downloads into smaller chunks. You can specify which portion of a file you want to download by including a byte range in the Range HTTP header of your request. For example:

Range: bytes=500-999

Partial download functionality is provided by many client libraries via a Media Download service. Refer to the client library documentation for details.

Download files in a browser

If you'd like to provide users with a way to download a file directly from their web browser, you can use the URL provided in the browserUrl field of the File resource. You can redirect a user to this URL, or offer it as a clickable link. In either case, the user will need to be logged into a Google account with access to DDM Reporting and have the correct permissions to access the specified file, in order to start the download.

Java

File file = reporting.files().get(reportId, fileId).execute();
String browserUrl = file.getUrls().getBrowserUrl();

Send feedback about...

DoubleClick Campaign Manager
DoubleClick Campaign Manager