[
  {
    "path": ".gitignore",
    "content": "# Logs\nlogs\n*.log\nnpm-debug.log*\nyarn-debug.log*\nyarn-error.log*\n\n# Runtime data\npids\n*.pid\n*.seed\n*.pid.lock\n\n# Directory for instrumented libs generated by jscoverage/JSCover\nlib-cov\n\n# Coverage directory used by tools like istanbul\ncoverage\n\n# nyc test coverage\n.nyc_output\n\n# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)\n.grunt\n\n# Bower dependency directory (https://bower.io/)\nbower_components\n\n# node-waf configuration\n.lock-wscript\n\n# Compiled binary addons (https://nodejs.org/api/addons.html)\nbuild/Release\n\n# Dependency directories\nnode_modules/\njspm_packages/\n\n# TypeScript v1 declaration files\ntypings/\n\n# Optional npm cache directory\n.npm\n\n# Optional eslint cache\n.eslintcache\n\n# Optional REPL history\n.node_repl_history\n\n# Output of 'npm pack'\n*.tgz\n\n# Yarn Integrity file\n.yarn-integrity\n\n# dotenv environment variables file\n.env\n\n# next.js build output\n.next\n\n# OS files\n.DS_Store"
  },
  {
    "path": "README.md",
    "content": "# google-indexing-api-bulk\n\nCreated by Steve at [Journey Further SEO](https://www.journeyfurther.com/)\n\nRequires node.js - https://nodejs.org/en/download/\n\nThis script will help you index your website's pages in bulk, without having to manually request each URL for submission in the Search Console interface.\n\nFirst off you will need to set up access to the Indexing API in Google Cloud Platform - follow the instructions below.\n\nhttps://developers.google.com/search/apis/indexing-api/v3/prereqs\n\nOnce you have access to Indexing API you'll be able to download a public/private key pair JSON file, this contains all of your credentials and should be saved as \"service_account.json\".\n\nAdd the URLs to the urls.txt file that you need to be crawled/indexed.\n\n\n## Verify site ownership in Search Console to submit URLs for indexing\nIn this step, you'll verify that you have control over your web property.\n\nTo verify ownership of your site you'll need to add your service account email address (see service_account.json - client_email) and add it as an owner ('delegated') of the web property in Search Console.\n\nYou can find your service account email address in two places:\n- The client_email field in the JSON private key that you downloaded when you created your project.\n- The Service account ID column of the Service Accounts view in the Developer Console.\n- The email address has a format similar to the following:\n\nFor example, \"my-service-account@test-project-42.google.com.iam.gserviceaccount.com\".\n\nThen...\n\n1. Go to [Google Webmaster Central](https://www.google.com/webmasters/verification/home)\n2. Click your verified property\n3. Scroll down and click 'Add an owner'.\n4. Add your service account email address as an owner to the property.\n\n\n## Quotas\n\n100 URLs per request batch\n\n200 URLs per day\n"
  },
  {
    "path": "index.js",
    "content": "const fs = require('fs');\nvar request = require('request');\nvar { google } = require('googleapis');\nvar key = require('./service_account.json');\n\nconst jwtClient = new google.auth.JWT(\n  key.client_email,\n  null,\n  key.private_key,\n  ['https://www.googleapis.com/auth/indexing'],\n  null\n);\n\nconst batch = fs\n  .readFileSync('urls.txt')\n  .toString()\n  .split('\\n');\n\njwtClient.authorize(function(err, tokens) {\n  if (err) {\n    console.log(err);\n    return;\n  }\n\n  const items = batch.map(line => {\n    return {\n      'Content-Type': 'application/http',\n      'Content-ID': '',\n      body:\n        'POST /v3/urlNotifications:publish HTTP/1.1\\n' +\n        'Content-Type: application/json\\n\\n' +\n        JSON.stringify({\n          url: line,\n          type: 'URL_UPDATED'\n        })\n    };\n  });\n\n  const options = {\n    url: 'https://indexing.googleapis.com/batch',\n    method: 'POST',\n    headers: {\n      'Content-Type': 'multipart/mixed'\n    },\n    auth: { bearer: tokens.access_token },\n    multipart: items\n  };\n  request(options, (err, resp, body) => {\n    console.log(body);\n  });\n});\n"
  },
  {
    "path": "package.json",
    "content": "{\n  \"name\": \"bulk-indexing-api\",\n  \"version\": \"1.0.0\",\n  \"description\": \"\",\n  \"main\": \"index.js\",\n  \"scripts\": {\n    \"test\": \"echo \\\"Error: no test specified\\\" && exit 1\"\n  },\n  \"author\": \"\",\n  \"license\": \"ISC\",\n  \"dependencies\": {\n    \"fs\": \"0.0.1-security\",\n    \"googleapis\": \"^46.0.0\",\n    \"request\": \"^2.88.0\"\n  }\n}\n"
  },
  {
    "path": "service_account.json",
    "content": "\n//  Download private key json file from https://console.developers.google.com/iam-admin/serviceaccounts and save here\n\n"
  },
  {
    "path": "urls.txt",
    "content": "//  Add your URLs here"
  }
]