Edits history of script submission #16841 for ' Create a disk (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Create a disk
     * Add a new disk to an existing Linode.
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      linodeId: string,
      body: {
        authorized_keys?: string[];
        authorized_users?: string[];
        filesystem?: "raw" | "swap" | "ext2" | "ext3" | "ext4" | "initrd";
        image?: string;
        label?: string;
        root_pass?: string;
        size?: number;
        stackscript_data?: {};
        stackscript_id?: number;
      },
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/linode/instances/${linodeId}/disks`,
      );
    
      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 235 days ago