0

Delete a Load Balancer

by
Published Dec 20, 2024

To delete a load balancer instance, disassociating any Droplets assigned to it and removing it from your account, send a DELETE request to `/v2/load_balancers/$LOAD_BALANCER_ID`. A successful request will receive a 204 status code with no body in response. This indicates that the request was processed successfully.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 536 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Delete a Load Balancer
7
 * To delete a load balancer instance, disassociating any Droplets assigned to it
8
and removing it from your account, send a DELETE request to
9
`/v2/load_balancers/$LOAD_BALANCER_ID`.
10

11
A successful request will receive a 204 status code with no body in response.
12
This indicates that the request was processed successfully.
13

14
 */
15
export async function main(auth: Digitalocean, lb_id: string) {
16
  const url = new URL(
17
    `https://api.digitalocean.com/v2/load_balancers/${lb_id}`,
18
  );
19

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