0

Get Top Verified Bot Categories By HTTP Requests

by
Published Nov 16, 2023

Get top verified bot categories by HTTP requests, along with their corresponding percentage, over the total verified bot HTTP requests.

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 Top Verified Bot Categories By HTTP Requests
8
 * Get top verified bot categories by HTTP requests, along with their corresponding percentage, over the total verified bot HTTP requests.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  limit: string | undefined,
13
  name: string | undefined,
14
  dateRange: string | undefined,
15
  dateStart: string | undefined,
16
  dateEnd: string | undefined,
17
  asn: string | undefined,
18
  location: string | undefined,
19
  format: "JSON" | "CSV" | undefined
20
) {
21
  const url = new URL(
22
    `https://api.cloudflare.com/client/v4/radar/verified_bots/top/categories`
23
  );
24
  for (const [k, v] of [
25
    ["limit", limit],
26
    ["name", name],
27
    ["dateRange", dateRange],
28
    ["dateStart", dateStart],
29
    ["dateEnd", dateEnd],
30
    ["asn", asn],
31
    ["location", location],
32
    ["format", format],
33
  ]) {
34
    if (v !== undefined && v !== "") {
35
      url.searchParams.append(k, v);
36
    }
37
  }
38
  const response = await fetch(url, {
39
    method: "GET",
40
    headers: {
41
      "X-AUTH-EMAIL": auth.email,
42
      "X-AUTH-KEY": auth.key,
43
      Authorization: "Bearer " + auth.token,
44
    },
45
    body: undefined,
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53