🚀 Try IndexingNow free today! START FREE TRIALClaim free offer Now→
🛠️ Free Webmaster Utility

Google Indexing API Python Script Generator

Generate copy-pasteable Python scripts to automate URL submissions to Google Indexing API. Setup GCP Service Accounts credentials.

Python Submission Script
import json
import requests
from google.oauth2 import service_account
from google.auth.transport.requests import AuthorizedSession

# Google Indexing API details
SCOPES = ["https://www.googleapis.com/auth/indexing"]
ENDPOINT = "https://indexing.googleapis.com/v3/urlNotifications:publish"

# Load your private JSON credentials file
credentials_file = "service_account_credentials.json"

# Authenticate request
credentials = service_account.Credentials.from_service_account_file(
    credentials_file, scopes=SCOPES
)
session = AuthorizedSession(credentials)

# Submission payload
payload = {
    "url": "https://yoursite.com/blog-post",
    "type": "URL_UPDATED" # Use URL_DELETED to remove path
}

# Dispatch POST notification to Google API nodes
response = session.post(ENDPOINT, data=json.dumps(payload))
print("Response Status Code:", response.status_code)
print("Response JSON Body:", response.json())

Step-by-Step Python Integration Guide for Google Indexing API

Programmatic SEO networks, automated publishing scripts, and large e-commerce platforms require robust API pipelines to submit URLs to search engines at scale. The official Google Indexing API offers a direct channel to request crawling for individual URLs. This guide explains how to configure a Python script to authenticate your requests and automate your submission queues.

1. The Google Cloud Platform (GCP) Configuration Process

Before running any Python code, you must establish a service account in the Google Cloud Console and delegate index authority:

  • Create a GCP Project: Log into the Google Cloud Console, click the project dropdown, and create a new project.
  • Enable the Indexing API: Navigate to the API Library, search for the "Webmaster Indexing API", and click "Enable" for your project.
  • Generate Service Account Credentials: Go to "IAM & Admin" > "Service Accounts". Click "Create Service Account", fill in details, and assign the project role of Owner.
  • Download Private JSON Key: Click on the newly created service account, go to the "Keys" tab, select "Add Key" > "Create New Key", choose JSON format, and save the downloaded file as service_account_credentials.json in your project directory.
  • Delegate GSC Ownership: Copy the service account email (e.g., your-account@project.iam.gserviceaccount.com). Go to Google Search Console, select your property, go to Settings > Users and Permissions, and add the service account email as an Owner (full user permissions will fail).

2. Understanding Authentication and OAuth 2.0 in Python

The Google Indexing API requires all HTTP requests to be authenticated using an OAuth 2.0 access token. The token is generated using the private JSON credentials key file we downloaded. Our Python script uses the google-auth library to load the JSON file, authenticate with Google's OAuth servers, and retrieve a short-lived access token with the https://www.googleapis.com/auth/indexing scope. This token is then attached to the authorization header of every POST request sent to the API endpoint.

3. Payload Structure and Error Handling

The API payload requires two parameters: the target url and the submission type. The type can be URL_UPDATED (to request an index crawl for a new or modified page) or URL_DELETED (to notify Google that a page has been removed and should be purged from search results).

When running the script, you may encounter response status codes like 403 Permission Denied or 429 Too Many Requests. A 403 error indicates that the GSC Owner delegation step was missed or the domain URL in the payload does not match the GSC property. A 429 error means you have exceeded the default daily quota of 200 URL submissions. For programmatic platforms, implementing rate-limiting queues and exponential backoff retry algorithms inside your Python scripts is highly recommended to manage quota distribution efficiently.

Tired of managing scripts and JSON keys?

Let our automated sitemap watcher submit posts and catalog drops on autopilot.

Start Free Trial
Google Indexing API Python Script Generator | IndexingNow