0

Partially Update a VPC

by
Published Dec 20, 2024

To update a subset of information about a VPC, send a PATCH request to `/v2/vpcs/$VPC_ID`.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Partially Update a VPC
7
 * To update a subset of information about a VPC, send a PATCH request to
8
`/v2/vpcs/$VPC_ID`.
9

10
 */
11
export async function main(
12
  auth: Digitalocean,
13
  vpc_id: string,
14
  body: { name?: string; description?: string } & { default?: false | true },
15
) {
16
  const url = new URL(`https://api.digitalocean.com/v2/vpcs/${vpc_id}`);
17

18
  const response = await fetch(url, {
19
    method: "PATCH",
20
    headers: {
21
      "Content-Type": "application/json",
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: JSON.stringify(body),
25
  });
26
  if (!response.ok) {
27
    const text = await response.text();
28
    throw new Error(`${response.status} ${text}`);
29
  }
30
  return await response.json();
31
}
32