0
List fleet status aggregate details by dimension
One script reply has been approved by the moderators Verified

List details for devices using WARP, up to 7 days

Created by hugo697 624 days ago Viewed 22525 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 624 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * List fleet status aggregate details by dimension
8
 * List details for devices using WARP, up to 7 days
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  account_identifier: string,
13
  time_end: string | undefined,
14
  time_start: string | undefined,
15
  colo: string | undefined,
16
  device_id: string | undefined
17
) {
18
  const url = new URL(
19
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/dex/fleet-status/over-time`
20
  );
21
  for (const [k, v] of [
22
    ["time_end", time_end],
23
    ["time_start", time_start],
24
    ["colo", colo],
25
    ["device_id", device_id],
26
  ]) {
27
    if (v !== undefined && v !== "") {
28
      url.searchParams.append(k, v);
29
    }
30
  }
31
  const response = await fetch(url, {
32
    method: "GET",
33
    headers: {
34
      "X-AUTH-EMAIL": auth.email,
35
      "X-AUTH-KEY": auth.key,
36
      Authorization: "Bearer " + auth.token,
37
    },
38
    body: undefined,
39
  });
40
  if (!response.ok) {
41
    const text = await response.text();
42
    throw new Error(`${response.status} ${text}`);
43
  }
44
  return await response.text();
45
}
46