Google Ads API is returning to beta status. Please read our blog post for more details.

Ordering and Limiting Results

Ordering results

You can specify the order of rows in your response using the ORDER BY clause, which consists of one or more comma-separated sequences of:

FieldName ('ASC' | 'DESC')?

If you do not specify ASC or DESC after a field name, the Google Ads API will default to ASC.

The following ORDER BY clause sorts a campaign-level report by descending impressions and ascending campaign name:

ORDER BY metrics.impressions DESC, ASC

Ordering is not allowed:

  • By attributes of non-selected resources
  • By non-selected metrics
  • By non-selected segments
  • For fields of the following types:
    • Repeated fields
    • Attributes of repeated fields

Limiting the number of results

You can limit the total number of results returned using the LIMIT clause. Combining this with results ordering, you can produce "top N" reports, such as a report containing the five campaigns with the highest impressions over the last 30 days:

FROM campaign
ORDER BY metrics.impressions DESC

Filtering is not allowed:

  • On segments without selecting them, except for "core" date segment fields.
    • The core date segment fields are, segments.week, segments.month, segments.quarter, and segments.year.
  • On fields of any message type except primitives (e.g.: Int64Value, StringValue, etc.)
  • On attributes of repeated fields of any message type except primitives (e.g.: Int64Value, StringValue, etc.)

Send feedback about...

Google Ads API Beta
Google Ads API Beta
Need help? Visit our support page.