Search code examples
javascriptgoogle-search-consolegoogle-search-api

How can I complete site verification in Google Search Console (Webmaster Tools) API version 3?


I'm working with the Search Console API to add sites and get information from them once added. Unfortunately, the API Reference is rather sparse and so far all I can do is submit the site for initial verification - then once I upload the verification file or meta tag, I have to go log into the google account and click the "Verify" button manually, defeating the purpose of the API.

I know that previous versions of the API allowed you to complete the verification by sending another request. As the documentation for v3 is missing a large amount of information and is often incorrect in general, I'm hoping someone else knows how to do this.


Solution

  • Use Google Site Verification instead.

    Request:

    POST https://www.googleapis.com/siteVerification/v1/token?access_token=oauth2-token
    Content-Type: application/json
    
    {
      "verificationMethod": "META",
      "site": {
        "identifier": "http://www.example.com",
        "type": "SITE"
      }
    }
    

    Response:

    {
      "token": '<meta name="google-site-verification" content="lZgPSX9UM01PXeMi88RGdIrBpl7jLFCXL9RNt4N0mmo" />',
      "method": "META"
    }
    

    Read this for more information: https://developers.google.com/site-verification/v1/invoking#verify