0

Rebuild a Linode

by
Published Oct 17, 2025

Rebuilds a Linode you have the `read_write` permission to modify.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Rebuild a Linode
7
 * Rebuilds a Linode you have the `read_write` permission to modify.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  linodeId: string,
13
  body: {
14
    authorized_keys?: string[];
15
    authorized_users?: string[];
16
    booted?: false | true;
17
    disk_encryption?: "enabled" | "disabled";
18
    image?: string;
19
    metadata?: { user_data?: string };
20
    root_pass?: string;
21
    stackscript_data?: {};
22
    stackscript_id?: number;
23
  } & { type?: string },
24
) {
25
  const url = new URL(
26
    `https://api.linode.com/${apiVersion}/linode/instances/${linodeId}/rebuild`,
27
  );
28

29
  const response = await fetch(url, {
30
    method: "POST",
31
    headers: {
32
      "Content-Type": "application/json",
33
      Authorization: "Bearer " + auth.token,
34
    },
35
    body: JSON.stringify(body),
36
  });
37
  if (!response.ok) {
38
    const text = await response.text();
39
    throw new Error(`${response.status} ${text}`);
40
  }
41
  return await response.json();
42
}
43