Competitors API Documentation
Sign up for a free account to get 100 lookups every month.
Identify competitors of a domain to analyze market position and strategy. Comprehensive documentation is available for Python, Node.js, Ruby, and PHP, ensuring seamless integration into your projects.
import requests
class Xranks:
def __init__(self, api_key):
self.headers = {'Authorization': api_key}
self.base_domain = 'https://xranks.com/'
def get_data(self, domain):
url = self.base_domain + 'api/v1/domain/competitors'
params = {"domain": domain}
res = requests.get(url, headers=self.headers, params=params)
if 'error' in res.json():
raise Exception(res.json()['error'])
return res.json()
if __name__ == '__main__':
# visit this url to get your api key: https://xranks.com/profile/apikeys/
xranks = Xranks(api_key='YOUR_API_KEY')
domain = 'xranks.com'
print(xranks.get_data(domain))
const axios = require('axios');
class Xranks {
constructor(apiKey) {
this.apiKey = apiKey;
this.baseDomain = 'https://xranks.com/';
}
async getData(domain) {
const url = this.baseDomain + 'api/v1/domain/competitors';
try {
const response = await axios.get(url, {
headers: { 'Authorization': this.apiKey },
params: { domain: domain }
});
if (response.data.error) {
throw new Error(response.data.error);
}
return response.data;
} catch (error) {
throw new Error(error.message);
}
}
}
if (typeof require !== 'undefined' && require.main === module) {
// visit this url to get your api key: https://xranks.com/profile/apikeys/
const xranks = new Xranks('YOUR_API_KEY');
xranks.getData('xranks.com').then(data => console.log(data)).catch(error => console.error(error));
}
require 'net/http'
require 'json'
class Xranks
def initialize(api_key)
@api_key = api_key
@base_domain = 'https://xranks.com/'
end
def get_data(domain)
url = URI(@base_domain + 'api/v1/domain/competitors')
url.query = URI.encode_www_form(domain: domain)
req = Net::HTTP::Get.new(url)
req['Authorization'] = @api_key
res = Net::HTTP.start(url.hostname, url.port, use_ssl: true) { |http| http.request(req) }
response = JSON.parse(res.body)
raise response['error'] if response['error']
response
end
end
if __FILE__ == $0
# visit this url to get your api key: https://xranks.com/profile/apikeys/
xranks = Xranks.new('YOUR_API_KEY')
puts xranks.get_data('xranks.com')
end
<?php
class Xranks {
private $apiKey;
private $baseDomain;
public function __construct($apiKey) {
$this->apiKey = $apiKey;
$this->baseDomain = "https://xranks.com/";
}
public function getData($domain) {
$url = $this->baseDomain . "api/v1/domain/competitors";
$url .= "?" . http_build_query(["domain" => $domain]);
$curl = curl_init($url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
curl_setopt($curl, CURLOPT_HTTPHEADER, [
"Authorization: " . $this->apiKey
]);
$response = curl_exec($curl);
if (curl_errno($curl)) {
throw new Exception(curl_error($curl));
}
$decoded = json_decode($response, true);
if (isset($decoded["error"])) {
throw new Exception($decoded["error"]);
}
curl_close($curl);
return $decoded;
}
}
// visit this url to get your api key: https://xranks.com/profile/apikeys/
$xranks = new Xranks("YOUR_API_KEY");
try {
$domainRank = $xranks->getData("xranks.com");
echo "Domain Rank: ";
print_r($domainRank);
} catch (Exception $e) {
echo "Error: " . $e->getMessage();
}
?>