Remove Zone Hold

Stop enforcement of a zone hold on the zone, permanently or temporarily, allowing the creation and activation of zones with this zone's hostname.

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
 * Remove Zone Hold
8
 * Stop enforcement of a zone hold on the zone, permanently or temporarily, allowing the
9
creation and activation of zones with this zone's hostname.
10
 */
11
export async function main(
12
  auth: Cloudflare,
13
  zone_id: string,
14
  hold_after: string | undefined
15
) {
16
  const url = new URL(
17
    `https://api.cloudflare.com/client/v4/zones/${zone_id}/hold`
18
  );
19
  for (const [k, v] of [["hold_after", hold_after]]) {
20
    if (v !== undefined && v !== "") {
21
      url.searchParams.append(k, v);
22
    }
23
  }
24
  const response = await fetch(url, {
25
    method: "DELETE",
26
    headers: {
27
      "X-AUTH-EMAIL": auth.email,
28
      "X-AUTH-KEY": auth.key,
29
      Authorization: "Bearer " + auth.token,
30
    },
31
    body: undefined,
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