# Google Ads Query (GAQL) (`google-ads.query`)

Runs a read-only Google Ads Query Language (GAQL) report on a Google Ads account: any resources, fields, segments and metrics.

Docs: https://primaryapi.com/docs/api-reference/google-ads/query

- Endpoint: `POST https://api.primaryapi.com/v1/run/google-ads.query`
- Category: Search & SEO · Platform: `google-ads` · Kind: search · Status: live
- Price: 1 credit per call. Every call costs the same, including calls that were retried automatically.
- Billing unit: per successful call
- Reliability: routed to a healthy upstream and retried automatically when an attempt fails; live 30-day status: `GET https://api.primaryapi.com/v1/status/apis?sku=google-ads.query`
- Execution: synchronous (answers 202 only if it outlives the wait window)

## Input

| Field | Type | Required | Default | Constraints | Description |
|---|---|---|---|---|---|
| `customerId` | string | yes |  | pattern: ^(\d{3})-?(\d{3})-?(\d{4})$ | Google Ads customer (account) id, 10 digits with or without hyphens, e.g. "123-456-7890". List yours with google-ads.accounts. |
| `query` | string | yes |  | max 20000 chars | A Google Ads Query Language (GAQL) SELECT, e.g. "SELECT campaign.name, metrics.clicks FROM campaign WHERE segments.date DURING LAST_7_DAYS ORDER BY metrics.clicks DESC LIMIT 50". Read-only. |
| `limit` | integer | no | 100 | 1–1000 | Maximum number of results to return (1-1000, default 100). |
| `cursor` | string | no |  |  | Opaque pagination cursor: pass the previous response's nextCursor. |
| `loginCustomerId` | string | no |  | pattern: ^(\d{3})-?(\d{3})-?(\d{4})$ | Only when the connected Google account reaches `customerId` THROUGH a manager (MCC) account: that manager account’s id (10 digits). Sent as the login-customer-id header. Omit for accounts the Google account can open directly. |
| `connection` | string | no |  | max 200 chars | Which connected account to use when the workspace has several for this provider: the customId you gave it (exact), its connection id ("con_…"), its handle (login, email or @handle) or its name. Optional; prefer the customId or id, which never match two accounts. |

Unknown fields are rejected with `400 invalid_input`. The routing controls `preferLatencyUnderMs` and `maxCredits` may be sent in the same JSON body.

## Output

When `output.found` is `true`, `output.data` has this shape:

| Field | Type | Description |
|---|---|---|
| `customerId` | string |  |
| `rows` | object[] | One object per result row, keyed by resource (campaign, adGroup, metrics, segments…) in lowerCamelCase; 64-bit numbers are strings |
| `fieldMask` | string \| null | The fields Google returned, comma-separated |
| `nextCursor` | string \| null |  |

When the thing you asked about does not exist (or a search matches nothing) the call still succeeds: `output.found` is `false`, `output.data` is `null` and `output.reason` says why (`not_found`, `private`, `no_results`, …). Misses are free unless the notes below say misses are billed.

Pagination: pass the previous response’s `nextCursor` as `cursor` to get the next page; `nextCursor: null` means there are no more results.

## Example request

```bash
curl -sS -X POST "https://api.primaryapi.com/v1/run/google-ads.query" \
  -H "Authorization: Bearer $PRIMARYAPI_API_KEY" \
  -H "Content-Type: application/json" \
  -d '{"customerId":"123-456-7890","query":"SELECT campaign.name, campaign.id, metrics.clicks, metrics.impressions, metrics.cost_micros FROM campaign WHERE segments.date DURING LAST_7_DAYS ORDER BY metrics.clicks DESC"}'
```

## Example response

_Values are placeholders that follow the output schema; `credits` is what this call would cost at the usual price._

```json
{
  "output": {
    "found": true,
    "data": {
      "customerId": "1234567890",
      "rows": [
        {
          "campaign": {
            "resourceName": "customers/1234567890/campaigns/111",
            "name": "Brand - Search",
            "id": "111"
          },
          "metrics": {
            "clicks": "842",
            "impressions": "12904",
            "costMicros": "412500000"
          }
        },
        {
          "campaign": {
            "resourceName": "customers/1234567890/campaigns/222",
            "name": "Generic - Search",
            "id": "222"
          },
          "metrics": {
            "clicks": "311",
            "impressions": "25110",
            "costMicros": "688100000"
          }
        }
      ],
      "fieldMask": "campaign.name,campaign.id,metrics.clicks,metrics.impressions,metrics.costMicros",
      "nextCursor": null
    }
  },
  "provider": "PrimaryAPI",
  "credits": 1,
  "items": 2,
  "requestId": "req_01JBXK6Y2N9V8T4R3Q2P1M0A7Z",
  "nextCursor": null
}
```

## Pricing and reliability

- Usual price: 1 credit per call
- Price ceiling: the usual price, even when a call is retried. A quote’s `maxCredits` is the most a given call can cost; the `maxCredits` routing control caps it per call
- Live 30-day status, success rate, uptime and latency: `GET https://api.primaryapi.com/v1/status/apis?sku=google-ads.query`

## Errors to handle

`invalid_input`, `unauthorized`, `insufficient_balance`, `key_limit_reached`, `trial_cap_reached`, `forbidden`, `not_found`, `idempotency_conflict`, `rate_limited`, `all_sources_failed`, `service_unavailable`, `timeout`. See https://primaryapi.com/docs/errors.

## Notes

Runs as your connected Google account and needs the Google Ads capability (ads). Read-only: GAQL can only SELECT. Field names in the query are snake_case (metrics.cost_micros); the rows come back in lowerCamelCase (metrics.costMicros) and money is in micros (1,000,000 = one unit of the account currency). Manager accounts have no metrics: query a client account, passing the manager id as loginCustomerId. Add a LIMIT to keep large reports fast. A rejected query is an invalid input error (nothing is charged).

