0

Get an Alias

by
Published Apr 8, 2025

Retrieves an Alias for the given host name or alias ID.

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 an Alias
7
 * Retrieves an Alias for the given host name or alias ID.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  idOrAlias: string,
12
  from: string | undefined,
13
  projectId: string | undefined,
14
  since: string | undefined,
15
  until: string | undefined,
16
  teamId: string | undefined,
17
  slug: string | undefined,
18
) {
19
  const url = new URL(`https://api.vercel.com/v4/aliases/${idOrAlias}`);
20
  for (const [k, v] of [
21
    ["from", from],
22
    ["projectId", projectId],
23
    ["since", since],
24
    ["until", until],
25
    ["teamId", teamId],
26
    ["slug", slug],
27
  ]) {
28
    if (v !== undefined && v !== "" && k !== undefined) {
29
      url.searchParams.append(k, v);
30
    }
31
  }
32
  const response = await fetch(url, {
33
    method: "GET",
34
    headers: {
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: undefined,
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.json();
44
}
45