0

Get Deployment File Contents

by
Published Apr 8, 2025

Allows to retrieve the content of a file by supplying the file identifier and the deployment unique identifier. The response body will contain a JSON response containing the contents of the file encoded as base64.

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 File Contents
7
 * Allows to retrieve the content of a file by supplying the file identifier and the deployment unique identifier. The response body will contain a JSON response containing the contents of the file encoded as base64.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  id: string,
12
  fileId: string,
13
  path: string | undefined,
14
  teamId: string | undefined,
15
  slug: string | undefined,
16
) {
17
  const url = new URL(
18
    `https://api.vercel.com/v7/deployments/${id}/files/${fileId}`,
19
  );
20
  for (const [k, v] of [
21
    ["path", path],
22
    ["teamId", teamId],
23
    ["slug", slug],
24
  ]) {
25
    if (v !== undefined && v !== "" && k !== undefined) {
26
      url.searchParams.append(k, v);
27
    }
28
  }
29
  const response = await fetch(url, {
30
    method: "GET",
31
    headers: {
32
      Authorization: "Bearer " + auth.token,
33
    },
34
    body: undefined,
35
  });
36
  if (!response.ok) {
37
    const text = await response.text();
38
    throw new Error(`${response.status} ${text}`);
39
  }
40
  return await response.text();
41
}
42