0

Delete mTLS certificate

by
Published Nov 16, 2023

Deletes the mTLS certificate unless the certificate is in use by one or more Cloudflare services.

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
 * Delete mTLS certificate
8
 * Deletes the mTLS certificate unless the certificate is in use by one or more Cloudflare services.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  identifier: string,
13
  account_identifier: string
14
) {
15
  const url = new URL(
16
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/mtls_certificates/${identifier}`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "DELETE",
21
    headers: {
22
      "X-AUTH-EMAIL": auth.email,
23
      "X-AUTH-KEY": auth.key,
24
      "Content-Type": "application/json",
25
      Authorization: "Bearer " + auth.token,
26
    },
27
    body: undefined,
28
  });
29
  if (!response.ok) {
30
    const text = await response.text();
31
    throw new Error(`${response.status} ${text}`);
32
  }
33
  return await response.json();
34
}
35