Set Account Custom Nameserver Related Zone Metadata

Set metadata for account-level custom nameservers on a zone. If you would like new zones in the account to use account custom nameservers by default, use PUT /accounts/:identifier to set the account setting use_account_custom_ns_by_default to true.

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
 * Set Account Custom Nameserver Related Zone Metadata
8
 * Set metadata for account-level custom nameservers on a zone.
9

10
If you would like new zones in the account to use account custom nameservers by default, use PUT /accounts/:identifier to set the account setting use_account_custom_ns_by_default to true.
11

12
 */
13
export async function main(
14
  auth: Cloudflare,
15
  zone_identifier: string,
16
  body: { enabled?: boolean; ns_set?: number; [k: string]: unknown }
17
) {
18
  const url = new URL(
19
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/custom_ns`
20
  );
21

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