Prerequisites for the Indexing API

Before you can start using the Indexing API, there are a few things you need to do, if you haven't done them already:

Create a project for your client

Before you can send requests to the Indexing API, you need to tell Google about your client and activate access to the API. You do this by using the Google API Console to create a project, which is a named collection of settings and API access information, and register your application.

To get started using Indexing API, you need to first use the setup tool, which guides you through creating a project in the Google API Console, enabling the API, and creating credentials.

Create a service account

  1. Open the Service accounts page. If prompted, select a project.
  2. Click Create Service Account, enter a name and description for the service account. You can use the default service account ID, or choose a different, unique one. When done click Create.
  3. The Service account permissions (optional) section that follows is not required. Click Continue.
  4. On the Grant users access to this service account screen, scroll down to the Create key section. Click Create key.
  5. In the side panel that appears, select the format for your key: JSON is recommended.
  6. Click Create. Your new public/private key pair is generated and downloaded to your machine; it serves as the only copy of this key. For information on how to store it securely, see Managing service account keys.
  7. Click Close on the Private key saved to your computer dialog, then click Done to return to the table of your service accounts.

The following steps are only necessary if you want to grant G Suite domain-wide authority to the service account.

  1. Locate the newly-created service account in the table. Under Actions, click then Edit.
  2. In the service account details, click Show domain-wide delegation, then ensure the Enable G Suite Domain-wide Delegation checkbox is checked.
  3. If you haven't yet configured your app's OAuth consent screen, you must do so before you can enable domain-wide delegation. Follow the on-screen instructions to configure the OAuth consent screen, then repeat the above steps and re-check the checkbox.
  4. Click Save to update the service account, and return to the table of service accounts. A new column, Domain-wide delegation, can be seen. Click View Client ID, to obtain and make a note of the client ID.

Verify site ownership in Search Console

In this step, you'll verify that you have control over your web property.

To verify ownership of your site:

  1. Verify ownership of your property.
  2. After your property has been verified, add your service account email as a delegated owner. You can find your service account email address in two places:
    • The client_email field in the JSON private key that you downloaded when you created your project.
    • The Service account ID column of the Service Accounts view in the Developers Console.

    The email address has a format similar to the following:

    For example, "".

Get an access token

To call the Indexing API, the call must be authenticated with an OAuth token that you get in exchange for your private key. Google provides API client libraries to get OAuth tokens for a number of languages.


When submitting a request to the Indexing API, your request must:

  1. Use as the scope.
  2. Use one of the endpoints described in Using the API.
  3. Include the service account access token.
  4. Define the body of the request as described in Using the API.


The following examples show how to obtain an OAuth access token:


Obtains an OAuth token using the Google API Client library for Python:

from oauth2client.service_account import ServiceAccountCredentials
import httplib2

SCOPES = [ "" ]

# service_account_file.json is the private key that you created for your service account.
JSON_KEY_FILE = "service_account_file.json"

credentials = ServiceAccountCredentials.from_json_keyfile_name(JSON_KEY_FILE, scopes=SCOPES)

http = credentials.authorize(httplib2.Http())

# Define contents here as a JSON string.
# This example shows a simple update request.
# Other types of requests are described in the next step.

content = """{
  \"url\": \"\",
  \"type\": \"URL_UPDATED\"

response, content = http.request(ENDPOINT, method="POST", body=content)


Obtains an OAuth token using the API Client Library for Java:

String scopes = "";
String endPoint = "";

JsonFactory jsonFactory = new JacksonFactory();

// service_account_file.json is the private key that you created for your service account.
InputStream in = IOUtils.toInputStream("service_account_file.json");

GoogleCredential credentials =
  GoogleCredential.fromStream(in, this.httpTransport, jsonFactory).createScoped(Collections.singleton(scopes));

GenericUrl genericUrl = new GenericUrl(endPoint);
HttpRequestFactory requestFactory = this.httpTransport.createRequestFactory();

// Define content here. The structure of the content is described in the next step.
String content = "{"
  + "\"url\": \"\","
  + "\"type\": \"URL_UPDATED\","
  + "}";

HttpRequest request =
  requestFactory.buildPostRequest(genericUrl, ByteArrayContent.fromString("application/json", content));

HttpResponse response = request.execute();
int statusCode = response.getStatusCode();


Obtains an OAuth token using the API Client Library for PHP:

require_once 'google-api-php-client/vendor/autoload.php';

$client = new Google_Client();

// service_account_file.json is the private key that you created for your service account.

// Get a Guzzle HTTP Client
$httpClient = $client->authorize();
$endpoint = '';

// Define contents here. The structure of the content is described in the next step.
$content = '{
  "url": "",
  "type": "URL_UPDATED"

$response = $httpClient->post($endpoint, [ 'body' => $content ]);
$status_code = $response->getStatusCode();


Obtains an OAuth token using the Node.js Client Library:

var request = require("request");
var { google } = require("googleapis");
var key = require("./service_account.json");

const jwtClient = new google.auth.JWT(

jwtClient.authorize(function(err, tokens) {
  if (err) {
  let options = {
    url: "",
    method: "POST",
    // Your options, which must include the Content-Type and auth headers
    headers: {
      "Content-Type": "application/json"
    auth: { "bearer": tokens.access_token },
    // Define contents here. The structure of the content is described in the next step.
    json: {
      "url": "",
      "type": "URL_UPDATED"
  request(options, function (error, response, body) {
    // Handle the response

In addition to showing how to obtain a token, these examples show where you can add the body of the request message. For information about the types of calls you can make, and the structure of the message bodies for those calls, see Using the API.