Edits history of script submission #16825 for ' Clone a Linode (linode)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Linode = {
      token: string;
    };
    /**
     * Clone a Linode
     * You can clone your Linode's existing Disks or Configuration profiles to another Linode on your Account.
     */
    export async function main(
      auth: Linode,
      apiVersion: "v4" | "v4beta",
      linodeId: string,
      body: {
        backups_enabled?: false | true;
        configs?: number[];
        disks?: number[];
        group?: string;
        label?: string;
        linode_id?: number;
        metadata?: { user_data?: string };
        placement_group?: { id: number };
        private_ip?: false | true;
        region?: string;
        type?: string;
      },
    ) {
      const url = new URL(
        `https://api.linode.com/${apiVersion}/linode/instances/${linodeId}/clone`,
      );
    
      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