How to Check Keyword Positions with the Google Search Console API (Step-by-Step)

How to Check Keyword Positions with the Google Search Console API (Step-by-Step)
You can check keyword positions with the Google Search Console API by sending a request to the Search Analytics query method with the query dimension, a date range, and optionally filters. Each row that comes back includes clicks, impressions, CTR, and position. That's the whole idea. The details (authentication, row limits, and what "position" really means) are where most people get stuck, so this guide covers each one in order.
The API is free, it uses your real Google data, and it removes the 1,000-row cap of the Search Console interface. For anyone publishing content regularly, it's the cheapest way to build your own rank report.

What the API gives you (and what it doesn't)
The Search Analytics endpoint returns the same performance data you see under Performance > Search results in the Search Console interface. For each combination of dimensions you ask for, you get four metrics:
- clicks: how many times users clicked through to your site
- impressions: how many times your URL appeared in results
- ctr: clicks divided by impressions
- position: your average position for those impressions
What it isn't: a live rank tracker. You won't get a snapshot of "where do I rank right now for this keyword". You get averages over a date range, only for queries where you actually earned impressions. If you don't appear for a keyword, it won't show up at all. Data also lags by roughly two to three days, and you can reach back about 16 months.
That trade-off is fine for most teams. You're measuring real searcher exposure, not a simulated crawl from one location.
Step 1: Set up a Google Cloud project and enable the API
You need a Google Cloud project to make API calls. It takes about five minutes.
- Open the Google Cloud Console and create a new project (or pick an existing one).
- Go to APIs & Services > Library, search for Google Search Console API, and click Enable.
- Open APIs & Services > Credentials to create the credentials described in the next step.
There's no billing requirement for normal use. The API has quotas, but a typical small-business site won't come close to them. The limits are generous: around 1,200 queries per minute per site or user, and far higher per project per day.
Step 2: Choose an authentication method
You have two realistic options.
Service account (best for automation)
A service account is a robot identity with its own email address. You create it under Credentials > Create credentials > Service account, then generate a JSON key file. Next, open Search Console, go to Settings > Users and permissions, and add the service account's email as a user. Restricted permission is enough for reading data.
This is what I'd pick for scheduled scripts. No browser pop-ups, no expiring tokens to babysit.
OAuth 2.0 client (best for one-off scripts)
If you'd rather authenticate as yourself, create an OAuth client ID (type: Desktop app), download the client secret file, and run the consent flow once. Google stores a token you reuse afterward. It's quicker for a single analysis but clumsy for anything scheduled.
Both methods use the same scope:
https://www.googleapis.com/auth/webmasters.readonly
Step 3: Make your first request
Install the Python client libraries:
pip install google-api-python-client google-auth
Then connect with a service account and pull the top queries for the last 28 days:
from datetime import date, timedelta
from google.oauth2 import service_account
from googleapiclient.discovery import build
SCOPES = ['https://www.googleapis.com/auth/webmasters.readonly']
creds = service_account.Credentials.from_service_account_file(
'service-account.json', scopes=SCOPES
)
service = build('searchconsole', 'v1', credentials=creds)
SITE = 'sc-domain:example.com' # or 'https://example.com/'
end = date.today() - timedelta(days=3)
start = end - timedelta(days=27)
body = {
'startDate': start.isoformat(),
'endDate': end.isoformat(),
'dimensions': ['query'],
'rowLimit': 1000,
}
resp = service.searchanalytics().query(siteUrl=SITE, body=body).execute()
for row in resp.get('rows', []):
print(row['keys'][0], round(row['position'], 1), row['impressions'])
Two details matter here. First, the siteUrl must match your property exactly. A Domain property uses sc-domain:example.com. A URL-prefix property uses the full address with the trailing slash, such as https://example.com/. Get this wrong and you'll see a 403 or an empty response. Second, I end the range three days back because the freshest data is incomplete.
A single row in the raw response looks like this:
{
"keys": ["content calendar template"],
"clicks": 42,
"impressions": 1310,
"ctr": 0.032,
"position": 7.4
}

Dimensions and filters
The dimensions array controls how rows are grouped. You can combine these:
query: the search termpage: the ranking URLdate: one row per daycountry: three-letter country codedevice: desktop, mobile, or tabletsearchAppearance: rich result types, where available
Use ['query', 'page'] when you want to know which URL ranks for which keyword. Add date when you want a trend line. Every extra dimension multiplies the number of rows, so request only what you need.
Filtering with dimensionFilterGroups
Filters narrow the data before it reaches you. Each filter has a dimension, an operator, and an expression. The operators are equals, notEquals, contains, notContains, includingRegex, and excludingRegex.
Here's how to check a single keyword on mobile in the United States:
body = {
'startDate': start.isoformat(),
'endDate': end.isoformat(),
'dimensions': ['date'],
'dimensionFilterGroups': [{
'groupType': 'and',
'filters': [
{'dimension': 'query', 'operator': 'equals',
'expression': 'content calendar template'},
{'dimension': 'device', 'operator': 'equals',
'expression': 'MOBILE'},
{'dimension': 'country', 'operator': 'equals',
'expression': 'usa'},
],
}],
}
The result is a daily position series for that one keyword, which is the closest thing the API offers to a rank tracker. Filters inside one group are combined with AND. Country codes are lowercase three-letter ISO codes, and device values are uppercase.
A regex filter is handy for grouping a keyword family, for example includingRegex with how to|guide|tutorial on the query dimension to isolate informational searches. You can also filter on page with contains and /blog/ to separate blog posts from product pages.
Pagination and row limits
The rowLimit parameter accepts values up to 25,000 per request. The default is 1,000. If your site has more rows than that, you paginate with startRow.
def fetch_all(service, site, body, page_size=25000):
rows, start_row = [], 0
while True:
body['rowLimit'] = page_size
body['startRow'] = start_row
resp = service.searchanalytics().query(
siteUrl=site, body=body).execute()
batch = resp.get('rows', [])
rows.extend(batch)
if len(batch) < page_size:
break
start_row += page_size
return rows
The loop stops when a response comes back with fewer rows than you requested. Simple and reliable.
There's also a ceiling beyond pagination. Google documents a limit of roughly 50,000 rows per day per search type per site, sorted by clicks. For large sites, long-tail queries at the bottom of that list simply won't be returned. If you hit that wall, query one day at a time using a date filter, or slice by page or country, so each request stays under the cap.
How to read average position correctly
This is where most reports go wrong. The position value isn't "your rank". It's the average of the topmost position your site held in each impression, where 1 is the first result.
Three consequences follow.
Averages hide spread. A position of 6.0 might mean you sat at 6 every time. It might also mean you hit position 1 on half the impressions and position 11 on the other half. Break the data out by device, country, or date to see which one it is.
Grouping changes the number. With only the query dimension, position covers all your pages that appeared for that query. Add page and you get one position per URL. Both are correct; they answer different questions.
Don't average averages. If you roll rows up yourself, weight position by impressions:
def weighted_position(rows):
total = sum(r['impressions'] for r in rows)
if total == 0:
return None
return sum(r['position'] * r['impressions'] for r in rows) / total
A row with 5,000 impressions at position 3 should count far more than a row with 10 impressions at position 40.
Also expect personalization, location, and SERP features to blur the number. Treat position as a reliable direction (up or down over weeks), not a precise coordinate.
Practical examples worth running
Striking-distance keywords
These are queries ranking between positions 8 and 20 with real impression volume. A content refresh often moves them onto page one faster than writing something new.
rows = fetch_all(service, SITE, {
'startDate': start.isoformat(),
'endDate': end.isoformat(),
'dimensions': ['query', 'page'],
})
targets = [
r for r in rows
if 8 <= r['position'] <= 20 and r['impressions'] >= 100
]
targets.sort(key=lambda r: r['impressions'], reverse=True)
for r in targets[:25]:
print(r['keys'][0], r['keys'][1], round(r['position'], 1))
Before-and-after checks
Published or updated a post? Pull the query and page rows filtered to that URL for the 28 days before and the 28 days after. Compare weighted position and impressions. Wait at least two to four weeks before judging; early movement is noisy.
Cannibalization checks
Group by query and page, then look for queries where two or more of your URLs both get meaningful impressions. If positions alternate between them, you probably have two pages competing for one intent.

Common pitfalls
- Wrong property format.
sc-domain:for Domain properties, full URL with trailing slash for URL-prefix ones. This causes most "permission denied" errors, along with forgetting to add the service account as a user. - Anonymized queries. Google hides rare queries for privacy. Totals from the
querydimension will be lower than totals with no dimension. Don't treat the gap as a bug. - Pacific Time dates. Search Console dates follow Pacific Time, so a daily row may not match your local calendar day.
- Mixing data states. By default you get finalized data. Setting
dataStatetoallincludes fresh, still-changing numbers, which is useful for monitoring but misleading in reports. - Forgetting search type. The default is web search. Image, video, news, and Discover results need the
typeparameter set explicitly (the newer name issearchType). - Tiny samples. A position of 2.0 from 3 impressions means nothing. Set an impressions threshold before you act on any row.
- Ignoring seasonality. Compare against the same period last year, not just last month, if your niche is seasonal.
Alternatives to calling the API directly
You don't have to write code to benefit from this data.
- Search Console interface export. Fine for quick checks, but capped at 1,000 rows per view.
- Looker Studio connector. Free, no code, and good for dashboards. Large datasets get slow.
- Google Sheets add-ons. Handy for non-technical teams who want scheduled pulls into a spreadsheet.
- BigQuery bulk export. The best option for big sites. It exports full data daily without the row cap and lets you query with SQL, though it needs a Cloud setup and has storage costs.
- Third-party rank trackers. They check live positions from chosen locations and cover keywords you don't yet rank for. They cost money and sample data rather than reflect real impressions.
My usual advice: use Search Console data as your baseline truth and add a paid tracker only if you need competitor comparisons or monitoring of keywords with no impressions yet.
Turning positions into publishing decisions
Position data is only useful if it changes what you publish. A simple monthly loop works well:
- Pull queries and pages for the last 28 days.
- Flag striking-distance keywords and refresh those posts first.
- Spot topics where you get impressions but have no dedicated page, and queue new articles.
- Schedule everything on a content calendar so the work actually ships.
This is where automation pays off. Once your gap list is ready, an AI SEO writer can turn those keywords into drafts, and the AI blog generator can publish them straight to WordPress, Webflow, or Shopify. If you manage several properties, multi-site blog management keeps each site's keyword list and schedule separate, and the flat monthly article quota means a bigger backlog doesn't raise your bill.
Quick recap
Enable the Search Console API, authenticate with a service account, and send a searchAnalytics.query request with the dimensions and filters you need. Paginate with startRow, stay mindful of the 50,000-row daily ceiling, and weight position by impressions whenever you aggregate. Read the number as an average, not a rank. Run the striking-distance report once a month and you'll have a repeatable, free way to decide which pages to improve next.

