# ahrefs

> Ahrefs API Nodejs client

Latest version **0.1.0** (published 2015-09-05) · MIT license · 0 weekly downloads

## Install

```sh
npm install ahrefs
pnpm add ahrefs
yarn add ahrefs
bun add ahrefs
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.1.0 |
| Published | 2015-09-05 |
| First published | 2015-09-04 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Node | >=0.8.0 |
| Dependencies | 2 |
| Known vulnerabilities | 0 (+2 in 2 direct dependencies) |
| Install scripts | no |
| GitHub stars | 4 |
| Author | Yannick Bonnefond |
| Maintainers | ybonnefond |
| Keywords | ahrefs, ahrefs.com, seo, ahrefs api |

## Links

- npm: https://www.npmjs.com/package/ahrefs
- Repository: https://github.com/ybonnefond/node-ahrefs
- Issues: http://github.com/ybonnefond/node-ahrefs/issues
- npm.io page: https://npm.io/package/ahrefs

## Dependencies (2)

- [xml2js](https://npm.io/package/xml2js.md) ^0.4.10
- [request](https://npm.io/package/request.md) ^2.60.0

## Recent versions

- 0.1.0 (latest) — 2015-09-05
- 0.0.1 — 2015-09-04

## README

# Ahrefs

- [Get an Ahrefs authentication token](https://ahrefs.com/api/profile)
- [Ahrefs api documentation](https://ahrefs.com/api/documentation)

## installation

```bash
  npm install ahrefs
```

## API

@see [Api documentation](docs/api.md)


## Basic Usage

Require the module and pass your options:

```javascript
var ahrefs = require('ahrefs')({ token: '<YOUR TOKEN>' });
```

Available options:

- **token** {string} : Authentication token
- **url** {string} [optional] : Api url, Default: http://apiv2.ahrefs.com/,
- **validate** {boolean} [optional] : If set to true, the module will verify the column sets in the query and **throw** an error if the column does not exists


Build a query:
```javascript
var query = ahrefs.newQuery()
  // Aim of a request: a domain, a directory or a URL
  .target('ahrefs.com')
  // Mode of operation: exact, domain, subdomains or prefix
  .mode('domain')
  // Table to select data from, see https://ahrefs.com/api/documentation for a complete list
  .from('ahrefs_rank');
```

Make the request and get the result :

```javascript
// Make a get request
ahrefs.get(query, function(err, result){

});

// Make a post request
ahrefs.post(query, function(err, result){

});
```

## Complete Example

```javascript

var query = ahrefs.newQuery()
  .target('ahrefs.com')
  .mode('domain') // Mode of operation: exact, domain, subdomains or prefix
  .output('xml') // Output format
  .select('anchor', 'backlinks') // List of columns to select (can be set multiple times)
  .from('anchors') // Table to select data from:  https://ahrefs.com/api/documentation/anchors
  .where('lt', 'backlinks', 10) // "Where" condition to satisfy, Less than 10 backlinks
  .where('lt', 'refpages', 5) // Can set multiple where clause
  .having('anchor', 'word', 'link') // Having the word `link` in anchor text
  .orderBy('first_seen', 'last_visited:desc') // ordering first by first_seen ascending, then by last_visited descending. Can be set multiple times
  .limit(10) // return 10 rows
  .offset(5); // from row 5

// Run the query
ahrefs.get(query, function(err, result){
  // do something
  if (err instanceof ahrefs.ValidationError) {
    // handle validation error
  }
});
```

## Run tests

You must specify your token to run the test suite:

```bash
  TOKEN=<YOUR TOKEN> npm test
```

You can also run the tests agains your own target if needed (default is `ahrefs.com`):
```bash
  TARGET=<YOUR TARGET> TOKEN=<YOUR TOKEN> npm test
```

**All tests run using `ahrefs.com` domain and therefore does not cost a peny**

## Generate API documentation

```bash
  npm run-script doc
```

# Special Thanks
Developed for <a target="_blank" href="http://optimiz.me">Optimiz.me</a>, an online software designed to help working the SEO optimisation of your web site, by yourself, without the need of technical knowledge.

Développé pour <a target="_blank" href="http://optimiz.me">Optimiz.me</a>, un logiciel en ligne conçu pour aider à travailler l'optimisation du référencement de votre site web, par vous-même, sans besoin de connaissances techniques.

---
_Source: https://npm.io/package/ahrefs · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
