Showing posts with label reports. Show all posts
Showing posts with label reports. Show all posts

Discover v201109 - AdHoc Reports

Tuesday, November 15, 2011


AdHoc reports is one of the new features we introduced in v201109 of the AdWords API. AdHoc reports are free, synchronous and don’t require a stored report definition. This blog post explains this new feature and covers the best practices.

Downloading the report

AdHoc reports utilizes plain HTTP POST requests to generate reports synchronously from the AdWords API server. A raw HTTP request to download the reports is shown below:

POST /api/adwords/reportdownload/v201109 HTTP/1.1
HOST: adwords.google.com
clientCustomerId: XXX-XXX-XXXX
Content-Type: application/x-www-form-urlencoded
developerToken: XXXX
Authorization: GoogleLogin auth=XXX
returnMoneyInMicros: true
Content-Length: XXXX


__rdxml=URL_ENCODED_DEFINITION_XML

As shown, the report is downloaded by making a POST request to https://adwords.google.com/api/adwords/reportdownload/v201109. The clientCustomerId header specifies the client for which this report is being run. The Authorization header contains the authorization information for downloading the report. If you are using ClientLogin as the authorization method, this header takes the form
Authorization: GoogleLogin auth=AUTH_TOKEN_HERE
If you are using OAuth, the header takes the form
Authorization: OAuth OAUTH_SIGNATURE_HERE
The returnMoneyInMicros header tells the server whether to return money values in micros or not. This is true by default; if set to false, money values are downloaded in actual currency format. The developerToken header contains your AdWords API developer token. The Report Definition is written in XML format and is provided in the __rdxml parameter of the POST body. The request should be encoded in application/x-www-form-urlencoded or multipart/form-data format.

You may also use the GET method instead of POST to download reports by sending your request to https://adwords.google.com/api/adwords/reportdownload/v201109?__rdxml=URL_ENCODED_REPORT_DEFINITION_XML with the same headers as in the POST example. However, we recommend using POST over GET since GET requests are more likely to incur URL length limit errors.

Creating definition xml

A Report Definition corresponds to the serialized form of the ReportDefinition type. For instance, a Report Definition that downloads an AdGroup performance report for the last 7 days in CSV format would look like this:

  <reportDefinition>
    <selector>
      <fields>CampaignId</fields>
      <fields>Id</fields>
      <fields>Impressions</fields>
      <fields>Clicks</fields>
      <fields>Cost</fields>
      <predicates>
        <field>Status</field>
        <operator>IN</operator>
        <values>ENABLED</values>
        <values>PAUSED</values>
      </predicates>
    </selector>
    <reportName>Custom Adgroup Performance Report</reportName>
    <reportType>ADGROUP_PERFORMANCE_REPORT</reportType>
    <dateRangeType>LAST_7_DAYS</dateRangeType>
    <downloadFormat>CSV</downloadFormat>
  </reportDefinition>

Details about the supported report types and their field are available at http://code.google.com/apis/adwords/docs/appendix/reports.html.

Error codes

When downloading AdHoc reports, the AdWords API server responds with HTTP code 200 and report in the response body. In case of an error, one of the two different HTTP response code may be returned:

1. HTTP Status code is 400: This error occurs when the AdWords API server throws an API error. When this happens, the error message will be returned in the server response body. You need to examine your report definition XML and server response body and fix any errors before retrying the call. The response body would look like

!!!2|||-1|||Error message here???

An easy way to parse the error message is to match it against the regex pattern "\!\!\!([^\|]*)\|\|\|(.*)"

2. HTTP Status code is 500: This error implies that the server faced an issue while generating the report. Chances are that this is a temporary error and may go away if you retry the call after waiting for 30 seconds. However, if you get this error even after five retries, you should skip the download and report the issue on the forum.

Using the client libraries

All of the client libraries support AdHoc reports, and takes care of details like making requests with the right HTTP headers and encoding, constructing authorization headers, handling the HTTP response codes, etc. For instance, the DownloadAdHocReports.cs code example shows how to download AdHoc reports using AdWords API .NET library:

Support for cross-client reports

As mentioned in an earlier blog post, AdHoc reports do not support cross-client reports. If you wish to run reports against many clients, you can refer to this blog post for details.

We hope this blog post will help you use this new feature effectively. As usual, If you have any questions about downloading reports, you can ask us on the forum or our upcoming live Hangouts with the Developer Relations team.

  --Anash P. Oommen, AdWords API Team

UPDATE2: Developer Token Required In Report Downloads

Monday, November 14, 2011


A little over a week ago we published a blog post informing developers that we would begin requiring a developer token with report downloads to better allow us to monitor reports, and extended the deadline in an update. We are changing the deadline to Tuesday January 17th, 2012 to give our developers more time during the busy holiday season.

As mentioned in our prior update, the sandbox will still have this change as of November 16th. We strongly encourage you to use the time between November 16th and January 17th to make the change to your applications, test against the sandbox and move the change to production. The existing production report download will ignore the header until it is required, which means you can implement the changes before the deadline without it breaking your existing applications.

We will update the client libraries to help you implement this change before the November 16th change in the sandbox environment. Please see our report download documentation for more information regarding report downloads. If you have any questions or would like to discuss this change, please post on the forum or try to attend our Google+ Hangouts with members of the AdWords API Developer Relations Team.

, AdWords API Team

UPDATE: Developer Token Required In Report Downloads

Tuesday, November 08, 2011


Last Thursday we published a blog post informing developers that we would begin requiring a developer token with report downloads.  Due to developer feedback regarding the proposed date being so close to the upcoming Thanksgiving holiday in the US, we are changing the deadline to Tuesday November 29th.

We’d also like to clarify two additional points:

  • We will start requiring the developer token as an HTTP header for report downloads in the sandbox as of November 16th.  This will allow developers to make requests with the developer token as an HTTP header to ensure their application will continue to function as expected when the production server begins requiring the developer token.
  • While the production service will begin requiring the developer token on November 29th, you can provide this HTTP header today and the server will still accept the request.  This means you can add the developer token in advance of the deadline without fear that report download functionality will be interrupted.
We will update the client libraries to help you implement this change before the November 16th change in the sandbox environment.  Please see our report download documentation for more information regarding report downloads.  If you have any questions or would like to discuss this change, please post on the forum or try to attend our Google+ Hangouts with members of the AdWords API Developer Relations Team.

, AdWords API Team

ACTION REQUIRED: Developer Token Required In Report Downloads Starting 11/23

Thursday, November 03, 2011


We would like to announce an important change to the process of downloading reports from the AdWords API that will affect all report downloads for tools built on API versions post v13.  Currently, downloading reports costs no API units and has previously not required a developer token.  To allow us to better monitor usage of reports, we will start requiring a developer token when downloading reports.  Downloading reports will still cost zero API units.

All report downloads - whether they be AdHoc or pre-v201109, using either GET or POST - must provide the developer token as an HTTP header. Example formatting of header:

developerToken: 1a2B3c4D5e_-6v7w8x9y0z

If your application fails to provide the developer token as an HTTP header after November 23rd, it will receive the error message QuotaCheckError.INVALID_TOKEN_HEADER when downloading reports.

We will be publishing updates to the example and utility code in the client libraries to reflect this change.  Please see our report download documentation for more information regarding report downloads.  If you have any questions or would like to discuss this change, please post on the forum or try to attend our Google+ Hangouts with members of the AdWords API Developer Relations Team.

Kevin Winter, AdWords API Team

Downloading reports for lots of client accounts

Friday, October 28, 2011


Reporting has changed significantly with v201109. We’d like to take this opportunity to discuss how to download reports for lots of clients simultaneously. To download reports for a large number of client accounts, we recommend requesting the download of these reports simultaneously.

We recommend requesting no more than 10 reports concurrently and to use one thread for each concurrent download. If for some reason the report download fails, we recommend you retry after a short wait. The length of the wait should increase with the number of times the request has been tried (known as Exponential Backoff). This backoff algorithm helps prevent making too many requests to the server in a short period of time.

You should check the specific reason the download failed and only retry if it was a transient error (such as exceeding the rate limit) instead of retrying if the report definition XML was invalid. The HTTP Status of the response provides useful information:
  • HTTP Status 500 indicates there is a transient server side issue and the request can be retried after a delay. We retrying no more than 5 times for any given report.
  • HTTP Status 400 indicates there was a problem with the request (or the report itself) and retrying will not help.
  • HTTP Status 200 means the report download was successful.
With v201109 you should use Ad Hoc reports to download new reports. With this new feature, there is no need for stored ReportDefinitions. The XML describing a Report Definition is sent directly with report download. A developer token is required, but the API call accrues no costs (report downloads are now free!).

Another benefit of downloading reports in this fashion is you get data more quickly than with legacy cross-client reports. As soon as a report download succeeds, you can start processing the data by putting it into a database or performing further logic on the results.

We hope this discussion of best practices will help you with writing report download code in the future. We’ve published a reference implementation showing how to do this in java here. If you have any questions about downloading reports, you can ask us on the forum.

, AdWords API Team

Enhanced documentation for selectors and reports

Wednesday, June 22, 2011


We understand the importance of documentation when navigating a system as complex as the AdWords API; for this reason we’ve been working to expand our reference materials to include even more information.

First off, we’ve published a new Selector Fields page that provides information about the fields that can be used in generic selectors. This information was always available on an object’s individual reference page, but now we’ve aggregated it together across entire services for quicker lookups.


Additional information on how to migrate from the service-specific selectors used in versions v200909 through v201008 is available in the Selector Migration Reference.

Next, we’ve added more notes to the Report Types page to indicate which fields will prevent zero-impression rows from being returned in the downloaded report. In general, any field that is a property of an impression or click (such as the date, network, etc) will prevent rows with no impressions from being returned, but we decided to explicitly mark these fields so that the behavior is clear.


Finally, we’ve added new tips to our Best Practices Guide on topics such as deleting entities and using gzip compression. The guide is a great resource for developers starting an AdWords API project, but is also useful for established developers trying to increase the efficiency of their applications.

We’re always looking to expand and improve our documentation, so if you have any feedback for us please post it to the forum.

- Eric Koleda, AdWords API Team