Edit SSL Certificate Pack Validation Method

Edit SSL validation method for a certificate pack. A PATCH request will request an immediate validation check on any certificate, and return the updated status. If a validation method is provided, the validation will be immediately attempted using that method.

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
 * Edit SSL Certificate Pack Validation Method
8
 * Edit SSL validation method for a certificate pack. A PATCH request will request an immediate validation check on any certificate, and return the updated status. If a validation method is provided, the validation will be immediately attempted using that method.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  cert_pack_uuid: string,
13
  zone_identifier: string,
14
  body: {
15
    validation_method: "http" | "cname" | "txt" | "email";
16
    [k: string]: unknown;
17
  }
18
) {
19
  const url = new URL(
20
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/ssl/verification/${cert_pack_uuid}`
21
  );
22

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