0

Delete a Floating IP

by
Published Dec 20, 2024

To delete a floating IP and remove it from your account, send a DELETE request to `/v2/floating_ips/$FLOATING_IP_ADDR`. 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 Floating IP
7
 * To delete a floating IP and remove it from your account, send a DELETE request
8
to `/v2/floating_ips/$FLOATING_IP_ADDR`.
9

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

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

19
  const response = await fetch(url, {
20
    method: "DELETE",
21
    headers: {
22
      Authorization: "Bearer " + auth.token,
23
    },
24
    body: undefined,
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