Edits history of script submission #10785 for ' Delete an Existing Project (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Delete an Existing Project
     * To delete a project, send a DELETE request to `/v2/projects/$PROJECT_ID`. To
    be deleted, a project must not have any resources assigned to it. Any existing
    resources must first be reassigned or destroyed, or you will receive a 412 error.
    
    A successful request will receive a 204 status code with no body in response.
    This indicates that the request was processed successfully.
    
     */
    export async function main(auth: Digitalocean, project_id: string) {
      const url = new URL(`https://api.digitalocean.com/v2/projects/${project_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 536 days ago