Why automate sitemap submission
Every time you publish new content, update a sitemap, or restructure your URL hierarchy, you want Google to know about it. The manual process — logging into Search Console, navigating to Sitemaps, pasting the URL — takes minutes and is easy to forget. For sites that update frequently, forgetting can mean hours or days of indexing delay.
The Search Console API lets you submit sitemaps programmatically, making it possible to trigger submissions from a CMS webhook, a CI/CD pipeline, or a scheduled job.
The API endpoint
GSC's sitemap submission uses a single PUT request:
PUT https://www.googleapis.com/webmasters/v3/sites/{siteUrl}/sitemaps/{feedpath}
# Example:
PUT https://www.googleapis.com/webmasters/v3/sites/https%3A%2F%2Fexample.com%2F/sitemaps/https%3A%2F%2Fexample.com%2Fsitemap.xmlBoth siteUrl and feedpath must be URL-encoded. A successful submission returns HTTP 200 with an empty body.
Note
siteUrl must exactly match how the property is registered in Search Console — including the trailing slash and the protocol (https:// vs. http://).Authentication: service account vs. OAuth
The GSC API requires OAuth 2.0 authentication. There are two approaches:
- Service account — A server-to-server credential you create in Google Cloud Console. Best for automated pipelines. You grant the service account access to your GSC property directly. No user interaction needed.
- OAuth user token — A token tied to a real Google account that has GSC access. Requires an OAuth consent flow and periodic token refresh. Better for tools where you want a user to authorise access once.
For automated sitemap submission, a service account is almost always the right choice.
Service account setup (one-time)
- Open Google Cloud Console → IAM & Admin → Service Accounts
- Create a service account and download the JSON key file
- In Search Console, add the service account email as a full user on the property
- Enable the "Google Search Console API" in your Cloud project
Node.js submission example
import { google } from "googleapis";
const auth = new google.auth.GoogleAuth({
keyFilename: "service-account-key.json",
scopes: ["https://www.googleapis.com/auth/webmasters"],
});
const siteUrl = "https://example.com/";
const sitemapUrl = "https://example.com/sitemap.xml";
const client = await auth.getClient();
const webmasters = google.webmasters({ version: "v3", auth: client });
await webmasters.sitemaps.submit({
siteUrl,
feedpath: sitemapUrl,
});
console.log("Sitemap submitted successfully");Verifying the submission
After submitting, you can fetch the sitemap status to confirm it was processed:
const { data } = await webmasters.sitemaps.get({
siteUrl,
feedpath: sitemapUrl,
});
console.log("Last downloaded:", data.lastDownloaded);
console.log("URLs submitted:", data.contents?.[0]?.submitted);Tip
lastDownloadedfield will update once Google has fetched it. Use IndexPilot's GSC integration to track submission history without managing API credentials yourself.