0

Create an Object Storage bucket

by
Published Oct 17, 2025

Creates an Object Storage bucket in the specified data center ([region](https://techdocs.

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 an Object Storage bucket
7
 * Creates an Object Storage bucket in the specified data center ([region](https://techdocs.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  body: {
13
    acl?:
14
      | "private"
15
      | "public-read"
16
      | "authenticated-read"
17
      | "public-read-write";
18
    cors_enabled?: false | true;
19
    endpoint_type?: "E0" | "E1" | "E2" | "E3";
20
    label: string;
21
    region?: string;
22
    s3_endpoint?: string;
23
  },
24
) {
25
  const url = new URL(
26
    `https://api.linode.com/${apiVersion}/object-storage/buckets`,
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