Developer Guide

Google Search Console API Guide

A practical guide to accessing your GSC data programmatically. OAuth setup, code examples, rate limits, and common pitfalls.

1. Setting Up API Access

Enable the API

  1. 1Go to Google Cloud Console
  2. 2Create a new project (or select existing)
  3. 3Navigate to "APIs & Services" → "Library"
  4. 4Search for and enable "Google Search Console API"
  5. 5Go to "Credentials" and create OAuth 2.0 credentials

Required Scopes

https://www.googleapis.com/auth/webmasters.readonly

Use webmasters scope (without readonly) if you need write access for sitemaps.

2. Authentication (OAuth 2.0)

The GSC API uses OAuth 2.0 for authentication. You'll need to implement the OAuth flow to get access tokens for your users (or yourself).

Note: Service accounts don't work well with GSC. You need OAuth with user consent to access Search Console data.

OAuth Flow Overview

  1. 1. Redirect user to Google's consent screen
  2. 2. User grants permission to access their GSC data
  3. 3. Google redirects back with an authorization code
  4. 4. Exchange the code for access and refresh tokens
  5. 5. Use access token for API requests, refresh when expired

Token Refresh

Access tokens expire after 1 hour. Store the refresh token securely and use it to get new access tokens when needed.

3. Python Examples

Install Dependencies

pip install google-api-python-client google-auth-oauthlib

Get Clicks and Impressions

from googleapiclient.discovery import build
from google.oauth2.credentials import Credentials

# Setup credentials (from your OAuth flow)
creds = Credentials.from_authorized_user_file('token.json')
service = build('searchconsole', 'v1', credentials=creds)

# Query for last 7 days
request = {
    'startDate': '2025-01-01',
    'endDate': '2025-01-07',
    'dimensions': ['query'],
    'rowLimit': 100
}

response = service.searchanalytics().query(
    siteUrl='https://example.com',
    body=request
).execute()

for row in response.get('rows', []):
    query = row['keys'][0]
    clicks = row['clicks']
    impressions = row['impressions']
    print(f"{query}: {clicks} clicks, {impressions} impressions")

List All Properties

# Get all sites you have access to
site_list = service.sites().list().execute()

for site in site_list.get('siteEntry', []):
    print(site['siteUrl'], site['permissionLevel'])

4. JavaScript Examples

Install Dependencies

npm install googleapis

Node.js Example

const { google } = require('googleapis');

// Setup OAuth2 client with your credentials
const oauth2Client = new google.auth.OAuth2(
  CLIENT_ID,
  CLIENT_SECRET,
  REDIRECT_URI
);

// Set credentials (from your OAuth flow)
oauth2Client.setCredentials({
  access_token: 'your-access-token',
  refresh_token: 'your-refresh-token'
});

const searchconsole = google.searchconsole({
  version: 'v1',
  auth: oauth2Client
});

// Query search analytics
const response = await searchconsole.searchanalytics.query({
  siteUrl: 'https://example.com',
  requestBody: {
    startDate: '2025-01-01',
    endDate: '2025-01-07',
    dimensions: ['query'],
    rowLimit: 100
  }
});

response.data.rows?.forEach(row => {
  console.log(row.keys[0], row.clicks, row.impressions);
});

5. Rate Limits and Quotas

LimitValue
Queries per day50,000 per project
Queries per second~5 QPS recommended
Rows per request25,000 max

Watch out for:

  • • 429 errors when you hit rate limits
  • • Implement exponential backoff for retries
  • • Cache responses to reduce API calls

6. What Data You Can Access

Available via API

  • Search analytics (clicks, impressions, CTR, position)
  • URL inspection (limited)
  • Sitemaps
  • Index coverage summary

NOT Available via API

  • Core Web Vitals (use PageSpeed API)
  • Detailed crawl stats
  • Security issues
  • Manual actions

7. Common Gotchas

1. Data Delay

GSC data is 2-3 days behind. Don't query for today or yesterday — you'll get incomplete data or nothing at all.

2. Property URL Formats

The siteUrl format matters:

  • • Domain properties: sc-domain:example.com
  • • URL-prefix properties: https://example.com/ (with trailing slash)

3. Data Sampling

High-traffic sites may return sampled data. The totals won't match what you see in the GSC UI exactly.

4. Dimension Limits

You can't combine all dimensions in one query. For example, you can't get query + page + country + device all at once.

5. URL Encoding

Site URLs in API requests must be URL-encoded. Use encodeURIComponent() in JavaScript or urllib.parse.quote() in Python.

8. Alternatives to Building It Yourself

Building your own GSC dashboard is a great learning project. But if you just want aggregated data across multiple properties without maintaining code, there are alternatives.

SearchBird

Connects to your GSC via OAuth and shows all your properties in one dashboard. No API code to maintain, no rate limit handling, no token refresh logic.

Try SearchBird Free

Or keep building your own solution — both are valid choices depending on your needs.