0
Create Primary Zone Configuration
One script reply has been approved by the moderators Verified

Create primary zone configuration for outgoing zone transfers.

Created by hugo697 623 days ago Viewed 22535 times
0
Submitted by hugo697 Typescript (fetch-only)
Verified 623 days ago
1
type Cloudflare = {
2
  token: string;
3
  email: string;
4
  key: string;
5
};
6
/**
7
 * Create Primary Zone Configuration
8
 * Create primary zone configuration for outgoing zone transfers.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  zone_identifier: string,
13
  body: {
14
    id: { [k: string]: unknown };
15
    name: string;
16
    peers: unknown[];
17
    [k: string]: unknown;
18
  }
19
) {
20
  const url = new URL(
21
    `https://api.cloudflare.com/client/v4/zones/${zone_identifier}/secondary_dns/outgoing`
22
  );
23

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