0

List site deploys

by
Published Oct 17, 2025
Script netlify Verified

The script

Submitted by hugo697 Bun
Verified 235 days ago
1
//native
2
type Netlify = {
3
  token: string;
4
};
5
/**
6
 * List site deploys
7
 *
8
 */
9
export async function main(
10
  auth: Netlify,
11
  site_id: string,
12
  deploy_previews: string | undefined,
13
  production: string | undefined,
14
  state:
15
    | "new"
16
    | "pending_review"
17
    | "accepted"
18
    | "rejected"
19
    | "enqueued"
20
    | "building"
21
    | "uploading"
22
    | "uploaded"
23
    | "preparing"
24
    | "prepared"
25
    | "processing"
26
    | "processed"
27
    | "ready"
28
    | "error"
29
    | "retrying"
30
    | undefined,
31
  branch: string | undefined,
32
  latest_published: string | undefined,
33
  page: string | undefined,
34
  per_page: string | undefined,
35
) {
36
  const url = new URL(
37
    `https://api.netlify.com/api/v1/sites/${site_id}/deploys`,
38
  );
39
  for (const [k, v] of [
40
    ["deploy-previews", deploy_previews],
41
    ["production", production],
42
    ["state", state],
43
    ["branch", branch],
44
    ["latest-published", latest_published],
45
    ["page", page],
46
    ["per_page", per_page],
47
  ]) {
48
    if (v !== undefined && v !== "" && k !== undefined) {
49
      url.searchParams.append(k, v);
50
    }
51
  }
52
  const response = await fetch(url, {
53
    method: "GET",
54
    headers: {
55
      Authorization: "Bearer " + auth.token,
56
    },
57
    body: undefined,
58
  });
59
  if (!response.ok) {
60
    const text = await response.text();
61
    throw new Error(`${response.status} ${text}`);
62
  }
63
  return await response.json();
64
}
65