0

List deployments

by
Published Apr 8, 2025

List deployments under the authenticated user or team. If a deployment hasn't finished uploading (is incomplete), the `url` property will have a value of `null`.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * List deployments
7
 * List deployments under the authenticated user or team. If a deployment hasn't finished uploading (is incomplete), the `url` property will have a value of `null`.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  app: string | undefined,
12
  from: string | undefined,
13
  limit: string | undefined,
14
  projectId: string | undefined,
15
  target: string | undefined,
16
  to: string | undefined,
17
  users: string | undefined,
18
  since: string | undefined,
19
  until: string | undefined,
20
  state: string | undefined,
21
  rollbackCandidate: string | undefined,
22
  teamId: string | undefined,
23
  slug: string | undefined,
24
) {
25
  const url = new URL(`https://api.vercel.com/v6/deployments`);
26
  for (const [k, v] of [
27
    ["app", app],
28
    ["from", from],
29
    ["limit", limit],
30
    ["projectId", projectId],
31
    ["target", target],
32
    ["to", to],
33
    ["users", users],
34
    ["since", since],
35
    ["until", until],
36
    ["state", state],
37
    ["rollbackCandidate", rollbackCandidate],
38
    ["teamId", teamId],
39
    ["slug", slug],
40
  ]) {
41
    if (v !== undefined && v !== "" && k !== undefined) {
42
      url.searchParams.append(k, v);
43
    }
44
  }
45
  const response = await fetch(url, {
46
    method: "GET",
47
    headers: {
48
      Authorization: "Bearer " + auth.token,
49
    },
50
    body: undefined,
51
  });
52
  if (!response.ok) {
53
    const text = await response.text();
54
    throw new Error(`${response.status} ${text}`);
55
  }
56
  return await response.json();
57
}
58