Prerequisites
- Python 3.10 or higher
- Google Cloud account with billing enabled
- Website ownership verified in Google Search Console
Step 1: Create Google Cloud Project
- Go to Google Cloud Console
- Click on project dropdown and select “NEW PROJECT”
- Enter project name (e.g., “indexing-api-project”)
- Click “CREATE”
Step 2: Enable Google Indexing API
- In your new project, navigate to “APIs & Services” > “Library”
- Search for “Google Indexing API”
- Click on it and then click “ENABLE”
- Wait for the API to be enabled
Step 3: Create Service Account
- Go to “APIs & Services” > “Credentials”
- Click “+ CREATE CREDENTIALS” and select “Service Account”
- Enter service account name (e.g., “indexing-api-service”)
- Add description: “Service account for Google Indexing API submissions”
- Click “CREATE AND CONTINUE”
- Skip granting roles (not needed for this API)
- Click “DONE”
Step 4: Generate Service Account Key
- In the Credentials page, find your service account
- Click on the service account name
- Go to “KEYS” tab
- Click “ADD KEY” > “Create new key”
- Select “JSON” as key type
- Click “CREATE”
- The JSON key file will be downloaded automatically
- Rename it to
service-account-key.jsonand place it in the same directory as the script
Step 5: Verify Website Ownership
- Go to Google Search Console
- Add your property (e.g.,
https://rkoots.github.io/) - Verify ownership using any available method (HTML file, DNS, etc.)
- This step is required for the Indexing API to work
Step 6: Install Dependencies
pip install requests google-auth google-auth-httplib2 google-auth-oauthlib
Step 7: Configure Script
Edit the configuration variables at the top of index.py:
SERVICE_ACCOUNT_FILE: Path to your service account JSON keySITEMAP_URL: Your sitemap URL (default: https://rkoots.github.io/sitemap.xml)MAX_WORKERS: Number of concurrent threads (default: 5)
Step 8: Run the Script
python index.py
Important Notes
- The Indexing API has quota limits (600 requests per minute per project)
- Use
MAX_WORKERS=5andRATE_LIMIT_DELAY=1.0to stay within limits - Only submit URLs that you own and have verified in Search Console
- The script creates a log file
indexing_submission.logfor debugging - Failed submissions are retried automatically with exponential backoff
Troubleshooting
- 403 Forbidden: Ensure Indexing API is enabled and website is verified
- 401 Unauthorized: Check service account key file path and permissions
- 429 Too Many Requests: Reduce MAX_WORKERS or increase RATE_LIMIT_DELAY
- No URLs found: Verify sitemap URL is accessible and contains
<loc>tags
API Response Types
URL_UPDATED: Notify Google that a URL has been updatedURL_DELETED: Notify Google that a URL has been removed (not used in this script)
Security Considerations
- Keep your service account key file secure and never commit it to version control
- Add
service-account-key.jsonto your.gitignorefile - The key has access to submit URLs for your verified properties only