Pull Search Console data with a service account, no third-party tool
Make a service account in Google Cloud, add its address to each Search Console property as a user with Restricted permission, and call the API with a token you sign from its key. Restricted is read-only and is enough for both the Search Analytics API and the URL Inspection API. My script pulls every property it can see each morning, saves one file per property per day, and has kept a backfill from 1 July without a third-party tool or a Google client library.
Set it up
- In Google Cloud, create a project and enable the Google Search Console API.
- Create a service account in it and download a JSON key. Treat the key like a password. Keep it out of git, make it readable only by you (
chmod 600), and never print it. - In Search Console, open each property’s Settings → Users and permissions → Add user, paste the service account’s address (it ends in
iam.gserviceaccount.com) and pick Restricted.
Then check what it can see:
$ python3 gsc.py sites
siteRestrictedUser sc-domain:coparentmath.com
siteRestrictedUser sc-domain:buyingcosts.com
siteRestrictedUser sc-domain:rubric.hrih.si
siteRestrictedUser sc-domain:hrih.si
A domain property is named sc-domain:example.com, and a URL-prefix property is named by its URL, https://example.com/. Both go into API paths URL-encoded.
Sign the token yourself
A service account signs a JWT with its private key and trades it for an hour-long access token (Google’s guide to the flow). In Python it takes the cryptography package and the standard library:
claims = {"iss": key["client_email"], "aud": key["token_uri"], "iat": now, "exp": now + 3600,
"scope": "https://www.googleapis.com/auth/webmasters.readonly"}
unsigned = f"{b64(header)}.{b64(claims)}"
private = serialization.load_pem_private_key(key["private_key"].encode(), password=None)
signature = b64(private.sign(unsigned.encode(), padding.PKCS1v15(), hashes.SHA256()))
# POST to key["token_uri"]: grant_type=urn:ietf:params:oauth:grant-type:jwt-bearer, assertion=<unsigned>.<signature>
Every call then sends Authorization: Bearer <token>. A day’s totals for one property:
POST https://www.googleapis.com/webmasters/v3/sites/sc-domain%3Ahrih.si/searchAnalytics/query
{"startDate": "2026-11-04", "endDate": "2026-11-04", "dataState": "final", "rowLimit": 25000}
Add "dimensions": ["query"], ["page"] or ["query", "page"] for the breakdowns. 25,000 rows is the most one request returns, and startRow pages past it. None of my sites gets near it.
Pull the day three days back
The numbers for a day keep changing for a couple of days. With "dataState": "final" the API returns only finished data, so a pull at 07:00 UTC asks for the day three days earlier. Each run saves the totals plus the rows by query, page, query and page, country and device, as data/gsc/<site>/<date>.json, and skips days already saved. A backfill is then the same command with --from 2026-07-01. Search Console keeps 16 months, so start the backfill before you lose any.
It runs as a systemd user timer on a small VM:
[Timer]
OnCalendar=*-*-* 07:00:00 UTC
Persistent=true
Persistent=true runs a missed pull after the VM was down. Failures go to ntfy. Four months for every property take 3.7 MB.
Ask Google whether a page is indexed
The same token works with the URL Inspection API, which answers what the inspect box in Search Console shows:
$ python3 gsc.py inspect sc-domain:hrih.si https://hrih.si/notes/ubuntu-server-root-volume-half-the-disk/
"coverageState": "Submitted and indexed",
"lastCrawlTime": "2026-11-03T09:08:18Z",
"googleCanonical": "https://hrih.si/notes/ubuntu-server-root-volume-half-the-disk/"
A weekly job runs it over every URL in each sitemap and lists the pages Google hasn’t indexed yet. It’s also how I found out that Google had picked the right canonical for a tagged link it had been showing as a second home page.
Bing’s numbers come through a simpler door, one API key in the query string.