0

List all the domains

by
Published Apr 8, 2025

Retrieves a list of domains registered for the authenticated user or team. By default it returns the last 20 domains if no limit is provided.

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 all the domains
7
 * Retrieves a list of domains registered for the authenticated user or team. By default it returns the last 20 domains if no limit is provided.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  limit: string | undefined,
12
  since: string | undefined,
13
  until: string | undefined,
14
  teamId: string | undefined,
15
  slug: string | undefined,
16
) {
17
  const url = new URL(`https://api.vercel.com/v5/domains`);
18
  for (const [k, v] of [
19
    ["limit", limit],
20
    ["since", since],
21
    ["until", until],
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.json();
41
}
42