All Collections
API
How to build an API query using Ahrefs API Request Builder
How to build an API query using Ahrefs API Request Builder

A brief instruction on using our internal request builder for creating an API request

Anna avatar
Written by Anna
Updated over a week ago

This article references the legacy version of our API (v2). Our newest API version (v3) was released on Sep. 7, 2022 and is available for Enterprise users.

Please feel free to contact [email protected] for more details.

This article will highlight the basics of creating an API request with the help of our API Request Builder.

First lets look through the builder itself to see what options it contains:

  • Token - required field. Should be generated here .

  • Target - required field. This should be a website, path or URL for which you are requesting data.

  • Mode - required field. You may choose from subdomains, domain, exact and prefix. We have a detailed explanation on the difference between all these modes in our video.

  • From - required field. This is an API function you will be requesting data from.

  • Limit (where applicable). By default it’s set to 1,000 with a maximum limit of 5M rows per request. Note: you will only be charged for the exact amount of returned rows .

  • Output. You may choose the output for your query. Available options include: json (default one), xml, php.

  • More Options: the set of available options here will vary depending on the chosen API query.

Here you can also set “where/having” parameters, as well as choose Order by and Order

At the end you will see an API query made in accordance with your choices made above.

Now let’s create a simple API query following the above guide to get backlinks for ahrefs.com domain (note: all requests made with ahrefs.com and its subdomains as a target are totally free of charge, so feel free to use this domain for your tests).

So here we go:

  • Target: ahrefs.com

  • Mode: subdomains

  • From: backlinks

  • Limit: 50

  • Output: json

  • Where: we are checking backlinks with the anchor “ahrefs”

  • Order by: Domain Rating

  • Order: Desc (to get the highest DR domains first)

API Request Builder will do the job for you encoding the data and here’s the query we will get based on our input: https://apiv2.ahrefs.com/?token=XXX&target=ahrefs.com&limit=50&output=json&from=backlinks&mode=subdomains&where=title%3D"ahrefs"&order_by=domain_rating:desc

Video tutorial:

Did this answer your question?