0

Purchase a domain

by
Published Apr 8, 2025

Allows to purchase the specified domain.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Purchase a domain
7
 * Allows to purchase the specified domain.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  teamId: string | undefined,
12
  slug: string | undefined,
13
  body: {
14
    name: string;
15
    expectedPrice?: number;
16
    renew?: false | true;
17
    country: string;
18
    orgName?: string;
19
    firstName: string;
20
    lastName: string;
21
    address1: string;
22
    city: string;
23
    state: string;
24
    postalCode: string;
25
    phone: string;
26
    email: string;
27
  },
28
) {
29
  const url = new URL(`https://api.vercel.com/v5/domains/buy`);
30
  for (const [k, v] of [
31
    ["teamId", teamId],
32
    ["slug", slug],
33
  ]) {
34
    if (v !== undefined && v !== "" && k !== undefined) {
35
      url.searchParams.append(k, v);
36
    }
37
  }
38
  const response = await fetch(url, {
39
    method: "POST",
40
    headers: {
41
      "Content-Type": "application/json",
42
      Authorization: "Bearer " + auth.token,
43
    },
44
    body: JSON.stringify(body),
45
  });
46
  if (!response.ok) {
47
    const text = await response.text();
48
    throw new Error(`${response.status} ${text}`);
49
  }
50
  return await response.json();
51
}
52