Submit Sitemaps with the Search Console API (Bulk Python Tool)

Search Console only submits sitemaps one at a time, by hand. I built a small Python tool on the Search Console API that submits a whole list in one run, and the setup taught me more than the code.

Project at a glance

Project
Bulk sitemap submission to Google Search Console
Problem
Search Console only submits sitemaps one at a time, by hand.
Stack
Python, Google Search Console API, a Google service account
How
Reads a text file of sitemap URLs and submits them all in one run, with retries and a CSV log.

How to submit a sitemap with the Search Console API

Use the sitemaps.submit method. It sends a PUT request to https://www.googleapis.com/webmasters/v3/sites/{siteUrl}/sitemaps/{feedpath}, where siteUrl is your exact property and feedpath is the full sitemap URL. URL-encode both when you call the endpoint directly; the Python client library does it for you. It needs the https://www.googleapis.com/auth/webmasters scope. A successful call returns an empty response body. See Google's official reference.

sitemaps.submit at a glance
FieldValue
Methodsitemaps.submit
HTTP requestPUT https://www.googleapis.com/webmasters/v3/sites/{siteUrl}/sitemaps/{feedpath}
siteUrlThe property exactly as in Search Console: https://example.com/ or sc-domain:example.com
feedpathThe full sitemap URL, for example https://example.com/sitemap.xml
OAuth scopehttps://www.googleapis.com/auth/webmasters
SuccessAn empty response body

With the Python client, one sitemap is one call:

Python
service.sitemaps().submit(
    siteUrl="sc-domain:example.com",
    feedpath="https://example.com/sitemap.xml"
).execute()

The rest of this post is the bulk version: how I turned that one call into a tool that submits a whole list.

Why I built a bulk tool

Google Search Console lets you submit sitemaps, but only one at a time, by hand. That's fine for a small site. When you're staring at dozens or hundreds of sitemaps, it turns into a slow, mind-numbing afternoon of copy and paste.

I ran into exactly this, so I built a small Python tool that reads a list of sitemap URLs and submits them all in one run. Here's how it works, the code behind it, and the setup traps that cost me more time than the code itself.

The problem

  • Search Console has no bulk-upload button for sitemaps.
  • I had a large batch to submit for one property.
  • Doing it by hand was slow and easy to get wrong.

Why the easy shortcuts don't work

Before writing any code, I checked the lazy routes:

Options for submitting many sitemaps
OptionDoes it work?Why
Sitemap “ping” URL✕ NoGoogle retired it. Hitting the URL does nothing now.
One sitemap index~ PartlyGoogle discovers every child sitemap from it, but Search Console only shows coverage and error stats per sitemap for sitemaps you submit directly.
Search Console API✓ YesIt has a method to submit each sitemap programmatically.

I wanted the per-file breakdown, so each sitemap had to be submitted on its own. That left the real solution: the Search Console API.

The approach

Three pieces make it work. Put your URLs in a file, run one command, and walk away.

The code

The core is small. The full version is on GitHub; here it's trimmed for reading. First, authenticate as the service account:

Python
from google.oauth2 import service_account
from googleapiclient.discovery import build

SCOPES = ["https://www.googleapis.com/auth/webmasters"]

def get_service():
    creds = service_account.Credentials.from_service_account_file(
        "service_account.json", scopes=SCOPES
    )
    return build("searchconsole", "v1", credentials=creds, cache_discovery=False)

Read the sitemap list from a text file, ignoring blank lines and comments:

Python
def load_from_file(path):
    with open(path, "r", encoding="utf-8") as f:
        return [line.strip() for line in f
                if line.strip() and not line.startswith("#")]

Submit a single sitemap, with retries for temporary errors:

Python
def submit_one(service, site_url, feedpath):
    for attempt in range(1, MAX_RETRIES + 1):
        try:
            service.sitemaps().submit(
                siteUrl=site_url, feedpath=feedpath
            ).execute()
            return "submitted", ""
        except HttpError as e:
            code = getattr(e.resp, "status", None)
            if code in (403, 404):
                return "failed", f"HTTP {code} (check owner permission / siteUrl)"
            if code in (429, 500, 502, 503) and attempt < MAX_RETRIES:
                time.sleep(DELAY_SECONDS * (2 ** attempt))
                continue
            return "failed", f"HTTP {code}: {e}"
    return "failed", "max retries exceeded"

This is what that function decides for every sitemap:

Then the main loop ties it together: load the list, submit each sitemap, and pause between requests. The full version also skips anything already submitted, writes a CSV log and can read a sitemap index.

Python
def main():
    sitemaps = load_from_file("sitemaps.txt")
    service = get_service()

    for url in sitemaps:
        status, detail = submit_one(service, SITE_URL, url)
        print(f"{status}: {url}")
        time.sleep(DELAY_SECONDS)

How it works, step by step

The script never reads the sitemaps itself. The submit call just tells Google “here's a sitemap, go look at it”, and Google fetches it later, on its own schedule.

Submitted doesn't mean valid

A “submitted” result means Google accepted the request, not that the sitemap is valid. Google fetches and checks the file afterwards, and any errors show up in the Sitemaps report hours later. They're two separate moments:

Does submitting a sitemap trigger indexing?

No. Submitting a sitemap is a discovery hint, not an indexing request. It tells Google the sitemap exists; Google fetches it and crawls the URLs on its own schedule, and then decides which pages to index. A successful API call only means the request was accepted.

There's no shortcut either: the old sitemap “ping” URL is retired, so the API (or the Sitemaps report in Search Console) is the way to submit. To see what Google did with the URLs afterwards, check the Page Indexing report filtered by sitemap. I automated that part too: tracking indexing per sitemap in BigQuery.

Search Console API errors: 403, 404, 429 and 5xx

Common sitemaps.submit errors, their likely causes and fixes
ErrorLikely causeFix
403 ForbiddenThe account lacks permission on the property, or the Search Console API isn't enabled in the Google Cloud project.Add the service account to the property (Owner is the safe choice) and enable the Google Search Console API for the project.
404 Not FoundThe siteUrl doesn't match a property the account can see, often a URL-prefix vs domain mix-up.Use the property exactly as Search Console lists it: https://example.com/ or sc-domain:example.com.
429 Too Many RequestsToo many requests in a short time.Pause between calls and retry with a growing wait (exponential backoff).
5xx (500, 503)A temporary error on Google's side.Retry with backoff. The script retries 500, 502 and 503 automatically.

Error meanings follow Google's Search Console API error reference. To check what access an account has, call sites.list: it returns each property with the account's permission level.

The traps that cost me the most time

The concept took an hour. The setup took a day, thanks to small, dumb obstacles. If you build this, these will slow you down:

  • Hidden file extensions on WindowsRenaming silently created service_account.json.json and sitemaps.txt.txt, so the script couldn't find them.Fix: Turn on “File name extensions” in Explorer before renaming, and check the real names with dir.
  • Python not on PATHThe classic. Commands fail even though Python is installed.Fix: Install with “Add to PATH” checked, then open a fresh terminal; open windows don't pick up the change.
  • The wrong property formatA URL-prefix property (https://example.com/) and a domain property (sc-domain:example.com) are different objects.Fix: Use the exact property format, or every submission fails with a 403 or 404.
  • Permission errors (403)Google's permissions table lists Owner and Full user as able to submit sitemaps, but my service account with Full access kept getting 403 errors from the API.Fix: Add the service account as an Owner of the property. That fixed it for me.
  • Corporate networks and proxiesThe API library uses an older HTTP library that doesn't detect a system proxy, so it can time out on a work network or VPN while the browser works fine.Fix: Route the API through the same proxy your system already uses.

The bigger lesson

The script was the easy part. The real work was everything around it: credentials, permissions, file naming and network quirks. That's true of most automation.

The logic is simple, and the plumbing is where the time goes.

If you're an SEO facing a pile of manual sitemap submissions, this is very doable. Budget your time for the setup, not the code.

nikhilsearch/gsc-sitemap-submitterThe full tool: skip-if-submitted, CSV log and sitemap-index option
ShareLinkedInX

Ask AI about this post

ChatGPTGeminiClaudeGrokPerplexity

Keep reading