//native
type Digitalocean = {
token: string;
};
/**
* Selectively Destroy a Droplet and its Associated Resources
* To destroy a Droplet along with a sub-set of its associated resources, send a
DELETE request to the `/v2/droplets/$DROPLET_ID/destroy_with_associated_resources/selective`
endpoint.
*/
export async function main(
auth: Digitalocean,
droplet_id: string,
body: {
floating_ips?: string[];
reserved_ips?: string[];
snapshots?: string[];
volumes?: string[];
volume_snapshots?: string[];
},
) {
const url = new URL(
`https://api.digitalocean.com/v2/droplets/${droplet_id}/destroy_with_associated_resources/selective`,
);
const response = await fetch(url, {
method: "DELETE",
headers: {
"Content-Type": "application/json",
Authorization: "Bearer " + auth.token,
},
body: JSON.stringify(body),
});
if (!response.ok) {
const text = await response.text();
throw new Error(`${response.status} ${text}`);
}
return await response.json();
}
Submitted by hugo697 536 days ago