0

Accept project transfer request

by
Published Apr 8, 2025

Accept a project transfer request initated by another team. The `code` is generated using the `POST /projects/:idOrName/transfer-request` endpoint.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Accept project transfer request
7
 * Accept a project transfer request initated by another team.  The `code` is generated using the `POST /projects/:idOrName/transfer-request` endpoint.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  code: string,
12
  teamId: string | undefined,
13
  slug: string | undefined,
14
  body: {
15
    newProjectName?: string;
16
    paidFeatures?: {
17
      concurrentBuilds?: number;
18
      passwordProtection?: false | true;
19
      previewDeploymentSuffix?: false | true;
20
    };
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.vercel.com/projects/transfer-request/${code}`,
25
  );
26
  for (const [k, v] of [
27
    ["teamId", teamId],
28
    ["slug", slug],
29
  ]) {
30
    if (v !== undefined && v !== "" && k !== undefined) {
31
      url.searchParams.append(k, v);
32
    }
33
  }
34
  const response = await fetch(url, {
35
    method: "PUT",
36
    headers: {
37
      "Content-Type": "application/json",
38
      Authorization: "Bearer " + auth.token,
39
    },
40
    body: JSON.stringify(body),
41
  });
42
  if (!response.ok) {
43
    const text = await response.text();
44
    throw new Error(`${response.status} ${text}`);
45
  }
46
  return await response.json();
47
}
48