Update a tunnel route (CIDR Endpoint)

Updates an existing private network route in an account. The CIDR in `ip_network_encoded` must be written in URL-encoded format.

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 a tunnel route (CIDR Endpoint)
8
 * Updates an existing private network route in an account. The CIDR in `ip_network_encoded` must be written in URL-encoded format.
9
 */
10
export async function main(
11
  auth: Cloudflare,
12
  ip_network_encoded: string,
13
  account_identifier: string
14
) {
15
  const url = new URL(
16
    `https://api.cloudflare.com/client/v4/accounts/${account_identifier}/teamnet/routes/network/${ip_network_encoded}`
17
  );
18

19
  const response = await fetch(url, {
20
    method: "PATCH",
21
    headers: {
22
      "X-AUTH-EMAIL": auth.email,
23
      "X-AUTH-KEY": auth.key,
24
      Authorization: "Bearer " + auth.token,
25
    },
26
    body: undefined,
27
  });
28
  if (!response.ok) {
29
    const text = await response.text();
30
    throw new Error(`${response.status} ${text}`);
31
  }
32
  return await response.json();
33
}
34