0

List Object Storage bucket contents

by
Published Oct 17, 2025

Returns the contents of a bucket.

Script linode Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Linode = {
3
  token: string;
4
};
5
/**
6
 * List Object Storage bucket contents
7
 * Returns the contents of a bucket.
8
 */
9
export async function main(
10
  auth: Linode,
11
  apiVersion: "v4" | "v4beta",
12
  regionId: string,
13
  bucket: string,
14
  marker: string | undefined,
15
  delimiter: string | undefined,
16
  prefix: string | undefined,
17
  page_size: string | undefined,
18
) {
19
  const url = new URL(
20
    `https://api.linode.com/${apiVersion}/object-storage/buckets/${regionId}/${bucket}/object-list`,
21
  );
22
  for (const [k, v] of [
23
    ["marker", marker],
24
    ["delimiter", delimiter],
25
    ["prefix", prefix],
26
    ["page_size", page_size],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45