0

Register or transfer-in a new Domain

by
Published Apr 8, 2025

This endpoint is used for adding a new apex domain name with Vercel for the authenticating user. Can also be used for initiating a domain transfer request from an external Registrar to Vercel.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Register or transfer-in a new Domain
7
 * This endpoint is used for adding a new apex domain name with Vercel for the authenticating user. Can also be used for initiating a domain transfer request from an external Registrar to Vercel.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  teamId: string | undefined,
12
  slug: string | undefined,
13
  body:
14
    | ({ method?: string } & {
15
        name: string;
16
        cdnEnabled?: false | true;
17
        zone?: false | true;
18
        method?: string;
19
      })
20
    | ({ method?: string } & { name: string; method: string; token?: string })
21
    | ({ method?: string } & {
22
        name: string;
23
        method: string;
24
        authCode?: string;
25
        expectedPrice?: number;
26
      }),
27
) {
28
  const url = new URL(`https://api.vercel.com/v5/domains`);
29
  for (const [k, v] of [
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: "POST",
39
    headers: {
40
      "Content-Type": "application/json",
41
      Authorization: "Bearer " + auth.token,
42
    },
43
    body: JSON.stringify(body),
44
  });
45
  if (!response.ok) {
46
    const text = await response.text();
47
    throw new Error(`${response.status} ${text}`);
48
  }
49
  return await response.json();
50
}
51