List SSL Configurations

List, search, and filter all of your custom SSL certificates. The higher priority will break ties across overlapping 'legacy_custom' certificates, but 'legacy_custom' certificates will always supercede 'sni_custom' certificates.

Script cloudflare Verified

by hugo697 ยท 11/16/2023

The script

Submitted by hugo697 Typescript (fetch-only)
Verified 383 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * List SSL Configurations
8
 * List, search, and filter all of your custom SSL certificates. The higher priority will break ties across overlapping 'legacy_custom' certificates, but 'legacy_custom' certificates will always supercede 'sni_custom' certificates.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  zone_identifier: string,
13
  page: string | undefined,
14
  per_page: string | undefined,
15
  match: "any" | "all" | undefined,
16
  status:
17
    | "active"
18
    | "expired"
19
    | "deleted"
20
    | "pending"
21
    | "initializing"
22
    | undefined
23
) {
24
  const url = new URL(
25
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/custom_certificates`
26
  );
27
  for (const [k, v] of [
28
    ["page", page],
29
    ["per_page", per_page],
30
    ["match", match],
31
    ["status", status],
32
  ]) {
33
    if (v !== undefined && v !== "") {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "GET",
39
    headers: {
40
      "X-AUTH-EMAIL": auth.email,
41
      "X-AUTH-KEY": auth.key,
42
      Authorization: "Bearer " + auth.token,
43
    },
44
    body: undefined,
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.json();
51
}
52