Common Use Case Example

We now take a look at a common use case: summarizing the performance of an account over the last 30 days by campaign, segmented by device. The query for this report is as follows:

SELECT
  campaign.name,
  campaign.status,
  segments.device,
  metrics.impressions,
  metrics.clicks,
  metrics.ctr,
  metrics.average_cpc,
  metrics.cost_micros
FROM campaign
WHERE segments.date DURING LAST_30_DAYS

To issue this request, pass the Google Ads Query Language statement above to the GoogleAdsService.SearchStream interface.

HTTP request URL

The request consists of an HTTP POST to the Google Ads API server at the following URL:

https://googleads.googleapis.com/v17/customers/{customer_id}/googleAds:searchStream

Complete HTTP request sample

Here is a complete example of the report definition above, enclosed in an HTTP POST request.

POST /v17/customers/{customer_id}/googleAds:searchStream HTTP/1.1
Host: googleads.googleapis.com
User-Agent: curl
Content-Type: application/json
Accept: application/json
Authorization: Bearer [Enter OAuth 2.0 access token here]
developer-token: [Enter developerToken here]

Parameters:
{
  "query" : "SELECT campaign.name, campaign.status, segments.device,
                    metrics.impressions, metrics.clicks, metrics.ctr,
                    metrics.average_cpc, metrics.cost_micros
            FROM campaign
            WHERE segments.date DURING LAST_30_DAYS"
}

Code samples

Watch a video walkthrough of a code sample that searches campaigns with metrics over the last 7 days. The code sample in the video is written in Java, but the process is similar for all languages.