Ahrefs is a comprehensive SEO tool that you can use for keyword research, backlink analysis, competitor analysis, keyword rank tracking, and as an SEO audit tool.
In this tutorial, I’ll teach you how to connect the Ahrefs API to Google Sheets in 5 steps:
Apipheny is an API connector for Google Sheets. You can use Apipheny to connect your Google Sheets to unlimited API data sources, make unlimited API requests, and more. There is a 30 day free trial included.
1.) Install Apipheny by opening the following link on desktop and then clicking the Install button in the Google Marketplace: https://apipheny.io/install
2.) After you’ve installed Apipheny, open a Google Sheet and then click on the Extensions dropdown in the menu at the top.
In the dropdown list you should see Apipheny. Click Apipheny then click Import API to open the Apipheny sidebar in your Google Sheet.
Tip: you can open a new Google Sheet by entering this URL in your browser: sheet.new
To generate your API key, go to your Ahrefs account name and click the Account settings option:
At the API keys section, click the Generate API key button:
Your API key is now generated:
Copy your API key to a safe location, because you’ll need it in the next steps.
Note: you have access to create an API key only if you upgrade to a paid subscription plan. You can’t create an API key on the free plan.
In this section, we’ll show you how to browse the Ahrefs API documentation to find an API endpoint URL that retrieves the information you need from your Ahrefs account.
If you already know your URL/endpoint and parameters, or you want to use the same example URL as us, just skip to Step 4.
To choose an endpoint, first open the Ahrefs API documentation page: https://ahrefs.com/api/documentation
On that page, you’ll see that the menu on the left contains general information and a list of endpoints for the Ahrefs API:
An example endpoint is the refdomains endpoint, that returns the referring domains that contain backlinks to the target:
https://api.ahrefs.com/v3/site-explorer/refdomains?from=refdomains&target=ahrefs.com&mode=domain&limit=3&output=json
The documentation for this endpoint contains a short description of the endpoint’s purpose, a table describing the accepted parameters, and a number of request examples:
All API calls to Ahrefs should be made to the https://apiv2.ahrefs.com base domain.
Ahrefs API root/base URL: https://api.ahrefs.com/v3/
The Top pages endpoint, which returns top pages:
Method: GET API URL Path: https://api.ahrefs.com/v3/site-explorer/top-pages?target=https%3A%2F%2Fapipheny.io%2F&output=json&date=2022-09-12&country=us&select=keywords,url Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_API_key Header 2 Key: Content-Type Header 2 Value: application/json
Make sure to replace your_API_key with the token you previously obtained and that your API URL Path contains all the required parameters. In this case, the required parameters are: date, select and target.
The Keywords history endpoint, which returns the history of the keywords:
Method: GET API URL Path: https://api.ahrefs.com/v3/site-explorer/keywords-history?target=https%3A%2F%2Fapipheny.io%2F&&output=json&date_from=2022-02-12 Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_API_key Header 2 Key: Content-Type Header 2 Value: application/json
Make sure to replace your_API_key with the token you previously obtained and that your API URL Path contains all the required parameters. In this case, the required parameters are: date_from and target.
The Backlinks stats endpoint, which returns the backlinks stats:
Method: GET API URL Path: https://api.ahrefs.com/v3/site-explorer/backlinks-stats?target=https%3A%2F%2Fapipheny.io%2F&&output=json&date=2022-02-12 Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_API_key Header 2 Key: Content-Type Header 2 Value: application/json
Make sure to replace your_API_key with the token you previously obtained and that your API URL Path contains all the required parameters. In this case, the required parameters are: date and target.
The Pages by traffic endpoint, which returns the pages by trafic:
Method: GET API URL Path: https://api.ahrefs.com/v3/site-explorer/pages-by-traffic?target=https%3A%2F%2Fapipheny.io%2F&&output=json&date=2022-02-12 Headers: Header 1 Key: Authorization Header 1 Value: Bearer your_API_key Header 2 Key: Content-Type Header 2 Value: application/json
Make sure to replace your_API_key with the token you previously obtained and that your API URL Path contains all the required parameters. In this case, the required parameter is target.
Now go back to your Google Sheet and make sure that the Apipheny add-on is open, on the Import tab.
In the Import Tab, enter these details into the add-on:
Method: At the top of the Apipheny sidebar, select the HTTP method (GET or POST) required by your API endpoint. For this example, we are using the GET method.
API URL: In Step 3, we explained how you can find the Ahrefs API endpoint that you need. Now copy the complete URL into the Apipheny add-on, where it says API URL Path, followed by any GET parameters required for your query.
For this example, we are using the Domain rating endpoint that returns the domain ratings and Ahrefs ranks. The URL for this API endpoint is:
https://api.ahrefs.com/v3/site-explorer/domain-rating
Headers: In the Headers section of the Apipheny add-on, add two rows with the following keys and values:
Header 1 Key: Authorization Value: Bearer your_API_key Header 2 Key: Content-Type Value: application/json
If you use this same endpoint URL, just keep in mind that your_API_key should be replaced with the value you generated in Step 2.
Finally, click the Run button at the bottom of the Apipheny add-on and then wait for the Ahrefs API data to be imported into your Google Sheet.
After making a successful request to the Ahrefs API, try querying a different endpoint, or try using one of the more advanced features in the Apipheny add-on.
If you’re an SEO consultant, this is a great way to organize data and create reports for clients. Your imagination is the limit.
Crypto API Tutorials: