To get the total count of indexed URLs for a domain using Google’s Custom Search API, you need to configure a Programmable Search Engine for that domain, then use the API to perform a site:
query, the response will include an estimated count of indexed pages in the totalResults
field.
This method is useful when you want a programmatic way to check how many of your site’s pages are visible to Google, especially helpful in SEO audits and index monitoring tasks.
Table of Contents
What Is Google Custom Search API?
Google Custom Search (now called Programmable Search Engine) lets you build a customized search engine that focuses only on a specific website or set of websites.
The Google Custom Search JSON API gives you access to this search engine programmatically, so you can send a search request via code and get structured results (in JSON format), including an estimate of how many results (i.e., indexed pages) exist for a query.
When used with a site:
query, this is a neat way to find out how many of your pages Google knows about.
Get Total Indexed URLs for a Domain Using Google Custom Search API
Step 1: Create a Programmable Search Engine for Your Domain
- Go to: Programmable Search Engine
- Click “Get Started” and create a new search engine.
- Under Sites to Search, enter your domain like this: CopyEdit
example.com
- Finish the setup and copy your Search Engine ID (
cx
), which you’ll need later.
Your custom engine is now restricted to search only within your domain. Perfect.
Step 2: Get Your API Key from Google Cloud
- Visit the Google Cloud Console
- Create a new project (or use an existing one).
- Navigate to APIs & Services > Library and search for: sqlCopyEdit
Custom Search API
Enable it. - Go to APIs & Services > Credentials and create an API Key.
Save this key, it authenticates your requests to the Custom Search API.
Step 3: Make the API Request
Here’s the format of the request URL:
arduinoCopyEdithttps://www.googleapis.com/customsearch/v1?key=YOUR_API_KEY&cx=YOUR_CX&q=site:example.com
Replace:
YOUR_API_KEY
with your actual API keyYOUR_CX
with your Search Engine IDexample.com
with your domain
This query searches only within your domain and tells you how many indexed URLs Google has for it.
Sample Response Breakdown
When you hit the endpoint, Google responds with structured JSON. Here’s the part you care about:
jsonCopyEdit"searchInformation": {
"searchTime": 0.234,
"formattedSearchTime": "0.23",
"totalResults": "215"
}
totalResults: "215"
means Google found 215 indexed pages for your domain.
That’s the number you came for!
Real-Life Use Case
Let’s say you’re doing an SEO audit for a client’s domain: clientsite.com
.
You want to know if Google is indexing most of the site’s pages.
You use:
bashCopyEdithttps://www.googleapis.com/customsearch/v1?key=XYZ&cx=ABC&q=site:clientsite.com
The response shows:
jsonCopyEdit"totalResults": "72"
But your CMS shows 300+ published pages, a red flag!
This is a quick and programmable way to identify indexing issues before deep-diving.
Things to Watch Out For
It’s an Estimate, Not Exact
Google returns an approximate number of results, not the exact count. But it’s still useful for spotting major differences.
API Quotas Apply
- Free Tier: 100 queries per day.
- Beyond Free: $5 per 1000 queries.
If you’re using it for one-off checks or for a few domains, the free tier is more than enough.
Only First 100 Results Are Fetchable
The API only lets you retrieve up to 100 search results per query, but the totalResults
field can go beyond that. This is fine since we’re just looking for the total count.
Bonus Tip: Automate It!
You can easily script this using:
- Python +
requests
module - Google Apps Script (for Google Sheets)
- Postman (for testing)
This makes it repeatable and ideal for reporting.
Using the Google Custom Search API is one of the easiest and most efficient ways to programmatically estimate how many of your pages are indexed by Google.
To recap:
- Set up a Programmable Search Engine for your domain
- Get your API key and cx ID
- Query using
site:yourdomain.com
- Read the
totalResults
field from the JSON response
It’s reliable, beginner-friendly, and great for audits, automation, or just keeping tabs on Google indexing over time.