0

Attach a volume

by
Published Oct 17, 2025

Attaches a Volume on your Account to an existing Linode 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
 * Attach a volume
7
 * Attaches a Volume on your Account to an existing Linode on your Account.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  volumeId: string,
13
  body: {
14
    config_id?: number;
15
    linode_id: number;
16
    persist_across_boots?: false | true;
17
  },
18
) {
19
  const url = new URL(
20
    `https://api.linode.com/${apiVersion}/volumes/${volumeId}/attach`,
21
  );
22

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