Edits history of script submission #10743 for ' Create a New VPC (digitalocean)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Digitalocean = {
      token: string;
    };
    /**
     * Create a New VPC
     * To create a VPC, send a POST request to `/v2/vpcs` specifying the attributes
    in the table below in the JSON body.
    
    **Note:** If you do not currently have a VPC network in a specific datacenter
    region, the first one that you create will be set as the default for that
    region. The default VPC for a region cannot be changed or deleted.
    
     */
    export async function main(
      auth: Digitalocean,
      body: { name?: string; description?: string } & {
        region?: string;
        ip_range?: string;
      },
    ) {
      const url = new URL(`https://api.digitalocean.com/v2/vpcs`);
    
      const response = await fetch(url, {
        method: "POST",
        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 537 days ago