0
Get DKIM Validations Time Series
One script reply has been approved by the moderators Verified

Percentage distribution of emails classified per DKIM validation over time.

Created by hugo697 297 days ago Viewed 8979 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 297 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Get DKIM Validations Time Series
8
 * Percentage distribution of emails classified per DKIM validation over time.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  aggInterval: "15m" | "1h" | "1d" | "1w" | 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
  arc: string | undefined,
20
  dmarc: string | undefined,
21
  spf: string | undefined,
22
  format: "JSON" | "CSV" | undefined
23
) {
24
  const url = new URL(
25
    `https://api.cloudflare.com/client/v4/radar/email/security/timeseries_groups/dkim`
26
  );
27
  for (const [k, v] of [
28
    ["aggInterval", aggInterval],
29
    ["name", name],
30
    ["dateRange", dateRange],
31
    ["dateStart", dateStart],
32
    ["dateEnd", dateEnd],
33
    ["asn", asn],
34
    ["location", location],
35
    ["arc", arc],
36
    ["dmarc", dmarc],
37
    ["spf", spf],
38
    ["format", format],
39
  ]) {
40
    if (v !== undefined && v !== "") {
41
      url.searchParams.append(k, v);
42
    }
43
  }
44
  const response = await fetch(url, {
45
    method: "GET",
46
    headers: {
47
      "X-AUTH-EMAIL": auth.email,
48
      "X-AUTH-KEY": auth.key,
49
      Authorization: "Bearer " + auth.token,
50
    },
51
    body: undefined,
52
  });
53
  if (!response.ok) {
54
    const text = await response.text();
55
    throw new Error(`${response.status} ${text}`);
56
  }
57
  return await response.json();
58
}
59