0

List aliases

by
Published Apr 8, 2025

Retrieves a list of aliases for the authenticated User or Team. When `domain` is provided, only aliases for that domain will be returned. When `projectId` is provided, it will only return the given project aliases.

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 aliases
7
 * Retrieves a list of aliases for the authenticated User or Team. When `domain` is provided, only aliases for that domain will be returned. When `projectId` is provided, it will only return the given project aliases.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  domain: string | undefined,
12
  from: string | undefined,
13
  limit: string | undefined,
14
  projectId: string | undefined,
15
  since: string | undefined,
16
  until: string | undefined,
17
  rollbackDeploymentId: string | undefined,
18
  teamId: string | undefined,
19
  slug: string | undefined,
20
) {
21
  const url = new URL(`https://api.vercel.com/v4/aliases`);
22
  for (const [k, v] of [
23
    ["domain", domain],
24
    ["from", from],
25
    ["limit", limit],
26
    ["projectId", projectId],
27
    ["since", since],
28
    ["until", until],
29
    ["rollbackDeploymentId", rollbackDeploymentId],
30
    ["teamId", teamId],
31
    ["slug", slug],
32
  ]) {
33
    if (v !== undefined && v !== "" && k !== undefined) {
34
      url.searchParams.append(k, v);
35
    }
36
  }
37
  const response = await fetch(url, {
38
    method: "GET",
39
    headers: {
40
      Authorization: "Bearer " + auth.token,
41
    },
42
    body: undefined,
43
  });
44
  if (!response.ok) {
45
    const text = await response.text();
46
    throw new Error(`${response.status} ${text}`);
47
  }
48
  return await response.json();
49
}
50