Update interconnect

Updates a specific interconnect associated with an account. Use `?validate_only=true` as an optional query parameter to only run validation without persisting changes.

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
 * Update interconnect
8
 * Updates a specific interconnect associated with an account. Use `?validate_only=true` as an optional query parameter to only run validation without persisting changes.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  tunnel_identifier: string,
13
  account_identifier: string,
14
  body: {
15
    description?: string;
16
    gre?: { cloudflare_endpoint?: string; [k: string]: unknown };
17
    health_check?: {
18
      enabled?: boolean;
19
      rate?: "low" | "mid" | "high";
20
      target?: string;
21
      type?: "reply" | "request";
22
      [k: string]: unknown;
23
    };
24
    interface_address?: string;
25
    mtu?: number;
26
    [k: string]: unknown;
27
  }
28
) {
29
  const url = new URL(
30
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/magic/cf_interconnects/${tunnel_identifier}`
31
  );
32

33
  const response = await fetch(url, {
34
    method: "PUT",
35
    headers: {
36
      "X-AUTH-EMAIL": auth.email,
37
      "X-AUTH-KEY": auth.key,
38
      "Content-Type": "application/json",
39
      Authorization: "Bearer " + auth.token,
40
    },
41
    body: JSON.stringify(body),
42
  });
43
  if (!response.ok) {
44
    const text = await response.text();
45
    throw new Error(`${response.status} ${text}`);
46
  }
47
  return await response.json();
48
}
49