0

List fleet status details by dimension

by
Published Nov 16, 2023

List details for live (up to 60 minutes) devices using WARP

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
 * List fleet status details by dimension
8
 * List details for live (up to 60 minutes) devices using WARP
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  account_identifier: string,
13
  since_minutes: string | undefined
14
) {
15
  const url = new URL(
16
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/dex/fleet-status/live`
17
  );
18
  for (const [k, v] of [["since_minutes", since_minutes]]) {
19
    if (v !== undefined && v !== "") {
20
      url.searchParams.append(k, v);
21
    }
22
  }
23
  const response = await fetch(url, {
24
    method: "GET",
25
    headers: {
26
      "X-AUTH-EMAIL": auth.email,
27
      "X-AUTH-KEY": auth.key,
28
      Authorization: "Bearer " + auth.token,
29
    },
30
    body: undefined,
31
  });
32
  if (!response.ok) {
33
    const text = await response.text();
34
    throw new Error(`${response.status} ${text}`);
35
  }
36
  return await response.json();
37
}
38