SCALIX help

← All tools

gads_run_gaql_query

Google Ads read low risk

Part of the Google Ads Manager Agent.

What it does

Execute an arbitrary Google Ads Query Language (GAQL) SELECT statement against a single customer account and return parsed rows. This is the universal read primitive behind every higher-level reporting tool: SELECT mixes resource attributes, metrics.* and segments.*; FROM names exactly one resource/view (campaign, ad_group, ad_group_ad, ad_group_criterion, keyword_view, search_term_view, geographic_view, customer, etc.); WHERE/ORDER BY/LIMIT/PARAMETERS follow that clause order. Uses GoogleAdsService.SearchStream (preferred for large reads; single request, server-streamed, no page tokens) and extracts ONLY the fields named in the SELECT clause to avoid token bloat. ACCURACY NOTES: money fields are in micros - divide cost_micros, average_cpc, cost_per_conversion, conversions_value by 1e6 before display and label the account currency (from gads_get_account_info); metrics.ctr/conversions_from_interactions_rate are already ratios (multiply by 100 only for percentage display); ROAS is conversions_value / (cost_micros/1e6) computed client-side; any segments.* in the SELECT multiplies/expands rows (e.g. segments.device, segments.date, segments.ad_network_type) so each row's metrics are the segment slice, not the entity total - never sum a segmented result and present it as the account total without the agent understanding the grouping; when a date comparison is requested, run two windows and report the prior-period delta. Returns {success, data:[rows], count, warnings}; a result cut at the 10,000-row cap says so in warnings, and an empty one says 'No rows match this query'. App campaign placements are not in group_placement_view or detail_placement_view (removed 5 Jan 2022): they are in group_content_suitability_placement_view and detail_content_suitability_placement_view (impressions and segments.date only). ERGONOMICS: DURING LAST_N_DAYS macros GAQL does not define (anything but 7/14/30, e.g. LAST_90_DAYS) are auto-translated to an explicit BETWEEN date range, and a WHERE/ORDER BY field missing from SELECT is auto-injected with a single retry — both noted in warnings. POSITIONING: advanced fallback — prefer the specific gads_get_*/gads_list_* reporting tools and never show raw GAQL to the user; translate their plain-English ask into the query yourself. GAQL syntax: https://developers.google.com/google-ads/api/docs/query/overview ; fields and resources: https://developers.google.com/google-ads/api/fields/v24/overview .

When to use it

When a question needs a custom GAQL query that no specific gads_get_*/gads_list_* tool answers — the advanced fallback for arbitrary SELECT statements. (In a full audit, gads_audit_account defines the checks this data feeds.)

Inputs

NameTypeRequiredDescription
customer_idstringyesTarget Google Ads account, 10 digits. Strip any dashes (123-456-7890 -> 1234567890) before sending - the API rejects hyphenated IDs. This is the account the query runs against, NOT the manager.
querystringyesA valid GAQL SELECT statement following clause order SELECT...FROM <one resource>...WHERE...ORDER BY...LIMIT...PARAMETERS. A trailing semicolon is stripped automatically; a query that does not start with SELECT is refused before the call. Do NOT request metrics.* against a manager (MCC) account (see manager-account error). Add an explicit LIMIT for large resources; segments in SELECT expand rows.
manager_idstringnoManager (MCC) customer ID, dashes stripped, sent as login-customer-id. Required only when the bearer account reaches the target through a manager; omit when the user's own credentials own the account. Obtain from gads_get_account_hierarchy / accessible-customers discovery.
page_sizeintegernoOptional server page size hint for streaming. Does not change total rows returned; results are still capped server-side by the tool's max-row safety limit.

Safeguards

Policy

Read-only reporting access under the single https://www.googleapis.com/auth/adwords scope (there is no separate read-only Ads scope; write tools are blocked at the app layer). Numbers returned MUST reconcile to the Google Ads UI within +/-1% (rounding only); never fabricate, extrapolate, or 'fill in' a metric the API did not return. Do not use this query primitive to read another tenant's account - the customer_id is bound to the server-derived bearer/tenant context and Postgres RLS; cross-account reads are prohibited.

Reminder

Match the Google Ads UI exactly; never invent a metric; search_term_view text and change_event user_email are sensitive - do not retain or client-expose account data beyond this request.

Errors

Error classMeansWhat to doRetry
INVALID_ARGUMENTThe GAQL query is invalid (e.g. query_error.UNRECOGNIZED_FIELD, bad FROM resource, or a selectability/segmentation mismatch). Surface the exact platform query_error.* / QueryError message; do not guess a correction.Return Google's verbatim error to the caller and ask it to fix the SELECT/FROM/WHERE; suggest checking field selectability/segmentability for the chosen resource.no
MANAGER_ACCOUNT_METRICS_NOT_QUERYABLEMetrics were requested against a manager (MCC) account (query_error.REQUESTED_METRICS_FOR_MANAGER); manager accounts hold no ad performance data - only client accounts do.Call gads_get_account_hierarchy to find client accounts under the MCC, then re-run with customer_id=<client> and manager_id=<mcc>.no
CUSTOMER_NOT_FOUNDThe customer_id does not exist or is not reachable with these credentials (CustomerError.CUSTOMER_NOT_FOUND).Verify via accessible-customers/hierarchy; if it was reachable before, the token may be revoked - re-auth (needs_reauth).no
TOKEN_REVOKEDThe OAuth token is expired, invalid, or revoked (UNAUTHENTICATED / AuthenticationError.OAUTH_TOKEN_REVOKED).Refresh the access token once and retry; if it still fails, prompt the user to re-authorize Google Ads (needs_reauth).yes
PERMISSION_DENIEDAuthorizationError.USER_PERMISSION_DENIED - the authenticated user lacks access to this account, or the requested data is out of the bearer token's granted scope.Confirm the user has access to this customer_id; do not retry with a different account silently.no
RESOURCE_EXHAUSTEDDaily-operations quota exceeded (QuotaError, HTTP 429).Stop retrying for the day if it is a daily cap; otherwise exponential backoff 5s -> 10s -> 20s (cap 60s) honoring any server retryDelay, then retry. Reduce query frequency.yes
RESOURCE_TEMPORARILY_EXHAUSTEDPer-second QPS rate limit hit (QuotaError.RESOURCE_TEMPORARILY_EXHAUSTED, HTTP 429).Back off 5/10/20s (cap 60s) honoring retryDelay, then retry; throttle concurrent requests for this CID + developer token.yes
PLATFORM_UNAVAILABLEGoogle Ads API internal/transient server error (InternalError.INTERNAL_ERROR / TRANSIENT_ERROR / DEADLINE_EXCEEDED, HTTP 5xx).Retry with backoff; if it persists across attempts, report a temporary Google-side outage.yes

Edge cases

  • Empty result set (valid query, no matching rows) -> success:true, count:0, data:[] with the note 'No rows match this query'; never invent placeholder values. A 0-row query FROM group_placement_view or detail_placement_view adds that App campaign placements left those views on 5 Jan 2022 and are in the content suitability views.
  • Query omits LIMIT on a large resource -> the stream stops at the 10,000-row cap and a warning says the results were truncated: add a LIMIT or a tighter WHERE/date range.
  • segments.* in SELECT multiplies rows (per device/date/network) - the same entity appears multiple times; metrics are per-segment, not totals; never sum across segments and label it an account total.
  • Cost/value fields are micros -> divide by 1e6; ctr/rate fields are already ratios; never double-divide.
  • Expired access token mid-call -> refresh once and retry the stream a single time before surfacing needs_reauth.
  • Manager/MCC customer_id with metrics in SELECT -> mapped to MANAGER_ACCOUNT_METRICS_NOT_QUERYABLE before the row loop.
  • Hyphenated customer_id supplied -> dashes stripped automatically before the call.
  • SearchStream has no page token; if a non-streamed Search fallback is used, follow next_page_token until exhausted (pagination follow-ups do not count as extra operations).
  • UNRECOGNIZED_FIELD comes verbatim from Google — the query passes through untouched (only a trailing semicolon is stripped); check field spelling and the FROM resource.
  • Custom columns made in the Google Ads UI cannot be selected in GAQL: Google's API exposes neither the columns nor their formulas.