How to Authenticate Your Site with IndexNow#
How to Set Up an API Key#
You need to create an API key and upload it to your website to verify ownership of your domain. The guide from Microsoft Bing is a good starting point. Once the API key is hosted on your website, the IndexNow API service can now authenticate your requests.
The API key will be required every time you submit a URL to any IndexNow API.
API Key Checklist
The example key a1b2c3d4
won't work, so try the API key generator from Microsoft Bing instead:
- Generate an API key.
- Upload a text file containing the API key to your website. This is the API key location.
Example of a key file:
The key file doesn't have to be named a1b2c3d4.txt
or placed in the root of your website, but this is considered the default location used by IndexNow. As long as the key file contains the API key a1b2c3d4
and the file location is referenced on every submission, your requests should be accepted:
If you're in any doubt, you can find more information about API keys in the official IndexNow documentation.
How to Use Authentication Credentials#
Once you have an API key and secured the location of the API key file, you can now update the IndexNowAuthentication
class with the authentication credentials and submit individual URLs to the IndexNow API:
Python | |
---|---|
Use the Same Authentication for Multiple Methods#
Whether you submit a single URL, multiple URLs, or an entire sitemap, the authentication credentials remain the same:
Tip
Because the API key and authentication credentials are required each time you submit URLs to the IndexNow API, it's a good idea to create an IndexNowAuthentication class once and reuse it in all your scripts. Then you won't have to repeat the authentication credentials each time you submit a URL or more.
For example, how to keep separate files in the same directory:
from index_now import IndexNowAuthentication
my_authentication = IndexNowAuthentication(
host="example.com",
api_key="a1b2c3d4",
api_key_location="https://example.com/a1b2c3d4.txt",
)