0

Create a Linode

by
Published Oct 17, 2025

Creates a Linode Instance on your Account.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * Create a Linode
7
 * Creates a Linode Instance on your Account.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  body: {
13
    authorized_keys?: string[];
14
    authorized_users?: string[];
15
    booted?: false | true;
16
    disk_encryption?: "enabled" | "disabled";
17
    image?: string;
18
    metadata?: { user_data?: string };
19
    root_pass?: string;
20
    stackscript_data?: {};
21
    stackscript_id?: number;
22
  } & {
23
    backup_id?: number;
24
    backups_enabled?: false | true;
25
    firewall_id?: number;
26
    group?: string;
27
    interfaces?: {
28
      active?: false | true;
29
      id?: number;
30
      ip_ranges?: string[];
31
      ipam_address?: string;
32
      ipv4?: { nat_1_1?: string; vpc?: string };
33
      label?: string;
34
      primary?: false | true;
35
      purpose: "public" | "vlan" | "vpc";
36
      subnet_id?: number;
37
      vpc_id?: number;
38
    }[];
39
    label?: string;
40
    placement_group?: { id?: number };
41
    private_ip?: false | true;
42
    region?: string;
43
    swap_size?: number;
44
    tags?: string[];
45
    type?: string;
46
  },
47
) {
48
  const url = new URL(`https://api.linode.com/${apiVersion}/linode/instances`);
49

50
  const response = await fetch(url, {
51
    method: "POST",
52
    headers: {
53
      "Content-Type": "application/json",
54
      Authorization: "Bearer " + auth.token,
55
    },
56
    body: JSON.stringify(body),
57
  });
58
  if (!response.ok) {
59
    const text = await response.text();
60
    throw new Error(`${response.status} ${text}`);
61
  }
62
  return await response.json();
63
}
64