0

Get deployment events

by
Published Apr 8, 2025

Get the build logs of a deployment by deployment ID and build ID. It can work as an infinite stream of logs or as a JSON endpoint depending on the input parameters.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Get deployment events
7
 * Get the build logs of a deployment by deployment ID and build ID. It can work as an infinite stream of logs or as a JSON endpoint depending on the input parameters.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  idOrUrl: string,
12
  direction: "backward" | "forward" | undefined,
13
  follow: "0" | "1" | undefined,
14
  limit: string | undefined,
15
  name: string | undefined,
16
  since: string | undefined,
17
  until: string | undefined,
18
  statusCode: string | undefined,
19
  delimiter: "0" | "1" | undefined,
20
  builds: "0" | "1" | undefined,
21
  teamId: string | undefined,
22
  slug: string | undefined,
23
) {
24
  const url = new URL(
25
    `https://api.vercel.com/v3/deployments/${idOrUrl}/events`,
26
  );
27
  for (const [k, v] of [
28
    ["direction", direction],
29
    ["follow", follow],
30
    ["limit", limit],
31
    ["name", name],
32
    ["since", since],
33
    ["until", until],
34
    ["statusCode", statusCode],
35
    ["delimiter", delimiter],
36
    ["builds", builds],
37
    ["teamId", teamId],
38
    ["slug", slug],
39
  ]) {
40
    if (v !== undefined && v !== "" && k !== undefined) {
41
      url.searchParams.append(k, v);
42
    }
43
  }
44
  const response = await fetch(url, {
45
    method: "GET",
46
    headers: {
47
      Authorization: "Bearer " + auth.token,
48
    },
49
    body: undefined,
50
  });
51
  if (!response.ok) {
52
    const text = await response.text();
53
    throw new Error(`${response.status} ${text}`);
54
  }
55
  return await response.text();
56
}
57