0

Get Domains Rank details

by
Published Nov 16, 2023

Gets Domains Rank details. Cloudflare provides an ordered rank for the top 100 domains, but for the remainder it only provides ranking buckets like top 200 thousand, top one million, etc.. These are available through Radar datasets endpoints.

Script cloudflare Verified

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 403 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Get Domains Rank details
8
 * Gets Domains Rank details. 
9
    Cloudflare provides an ordered rank for the top 100 domains, but for the remainder it only provides ranking buckets
10
    like top 200 thousand, top one million, etc.. These are available through Radar datasets endpoints.
11
 */
12
export async function main(
13
  auth: Cloudflare,
14
  domain: string,
15
  limit: string | undefined,
16
  rankingType: "POPULAR" | "TRENDING_RISE" | "TRENDING_STEADY" | undefined,
17
  name: string | undefined,
18
  date: string | undefined,
19
  format: "JSON" | "CSV" | undefined
20
) {
21
  const url = new URL(
22
    `https://api.cloudflare.com/client/v4/radar/ranking/domain/${domain}`
23
  );
24
  for (const [k, v] of [
25
    ["limit", limit],
26
    ["rankingType", rankingType],
27
    ["name", name],
28
    ["date", date],
29
    ["format", format],
30
  ]) {
31
    if (v !== undefined && v !== "") {
32
      url.searchParams.append(k, v);
33
    }
34
  }
35
  const response = await fetch(url, {
36
    method: "GET",
37
    headers: {
38
      "X-AUTH-EMAIL": auth.email,
39
      "X-AUTH-KEY": auth.key,
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: undefined,
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50