Edits history of script submission #10778 for ' Delete a VPC (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Delete a VPC
     * To delete a VPC, send a DELETE request to `/v2/vpcs/$VPC_ID`. A 204 status
    code with no body will be returned in response to a successful request.
    
    The default VPC for a region can not be deleted. Additionally, a VPC can only
    be deleted if it does not contain any member resources. Attempting to delete
    a region's default VPC or a VPC that still has members will result in a
    403 Forbidden error response.
    
     */
    export async function main(auth: Digitalocean, vpc_id: string) {
      const url = new URL(`https://api.digitalocean.com/v2/vpcs/${vpc_id}`);
    
      const response = await fetch(url, {
        method: "DELETE",
        headers: {
          Authorization: "Bearer " + auth.token,
        },
        body: undefined,
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.json();
    }
    

    Submitted by hugo697 537 days ago