DEV Community

Tugelbay Konabayev
Tugelbay Konabayev

Posted on • Originally published at about-kazakhstan.com

Automating Google Indexing API Submissions with Node.js

Why Manual Indexing Matters for New Sites

Google discovers pages through crawling, but new domains with low authority can wait weeks for pages to appear in search results. The Google Indexing API lets you proactively notify Google about new or updated URLs.

I built a Node.js script that checks which pages are indexed via the Search Console API, then submits non-indexed URLs to the Indexing API automatically.

Prerequisites

  • Google Cloud project with Indexing API enabled
  • Service account with Owner role in Search Console
  • googleapis npm package

The Architecture

Sitemap parsing, index status checking via GSC API, filtering non-indexed URLs, then batch submission via the Indexing API. The whole pipeline runs unattended.

Service Account Setup

import { google } from "googleapis";
import { readFileSync } from "fs";

const auth = new google.auth.GoogleAuth({
  keyFile: "data/google-service-account.json",
  scopes: ["https://www.googleapis.com/auth/indexing"]
});

const indexing = google.indexing({ version: "v3", auth });
Enter fullscreen mode Exit fullscreen mode

Fetching Sitemap URLs

async function getSitemapUrls(sitemapUrl) {
  const res = await fetch(sitemapUrl);
  const xml = await res.text();
  return [...xml.matchAll(/<loc>(.*?)<\/loc>/g)].map(m => m[1]);
}
Enter fullscreen mode Exit fullscreen mode

Checking Index Status

The URL Inspection API tells you whether Google has indexed each page:

async function checkIndexStatus(url, siteUrl) {
  const res = await webmasters.urlInspection.index.inspect({
    requestBody: { inspectionUrl: url, siteUrl }
  });
  return res.data.inspectionResult.indexStatusResult.coverageState;
}
Enter fullscreen mode Exit fullscreen mode

Submitting Non-Indexed URLs

async function submitUrl(url) {
  await indexing.urlNotifications.publish({
    requestBody: { url, type: "URL_UPDATED" }
  });
}
Enter fullscreen mode Exit fullscreen mode

Quota Management

The Indexing API allows 200 submissions per day. The script tracks submissions in a JSON log file to avoid duplicates and respect the daily limit.

Results

After running this daily for a week on a travel content site with 90 pages:

  • Index rate: 13% to 20%
  • Unknown URLs: 40 down to 23
  • Google started discovering pages within 24-48 hours

The Indexing API is free with a 200/day quota and dramatically speeds up discovery for new sites.

Top comments (0)