0

Delete a Firewall

by
Published Dec 20, 2024

To delete a firewall send a DELETE request to `/v2/firewalls/$FIREWALL_ID`. No response body will be sent back, but the response code will indicate success. Specifically, the response code will be a 204, which means that the action was successful with no returned body data.

Script digitalocean Verified

The script

Submitted by hugo697 Bun
Verified 537 days ago
1
//native
2
type Digitalocean = {
3
  token: string;
4
};
5
/**
6
 * Delete a Firewall
7
 * To delete a firewall send a DELETE request to `/v2/firewalls/$FIREWALL_ID`.
8

9
No response body will be sent back, but the response code will indicate
10
success. Specifically, the response code will be a 204, which means that the
11
action was successful with no returned body data.
12

13
 */
14
export async function main(auth: Digitalocean, firewall_id: string) {
15
  const url = new URL(
16
    `https://api.digitalocean.com/v2/firewalls/${firewall_id}`,
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