0

Update an existing project

by
Published Apr 8, 2025

Update the fields of a project using either its `name` or `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
 * Update an existing project
7
 * Update the fields of a project using either its `name` or `id`.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  idOrName: string,
12
  teamId: string | undefined,
13
  slug: string | undefined,
14
  body: {
15
    autoExposeSystemEnvs?: false | true;
16
    autoAssignCustomDomains?: false | true;
17
    autoAssignCustomDomainsUpdatedBy?: string;
18
    buildCommand?: string;
19
    commandForIgnoringBuildStep?: string;
20
    customerSupportCodeVisibility?: false | true;
21
    devCommand?: string;
22
    directoryListing?: false | true;
23
    framework?:
24
      | "blitzjs"
25
      | "nextjs"
26
      | "gatsby"
27
      | "remix"
28
      | "react-router"
29
      | "astro"
30
      | "hexo"
31
      | "eleventy"
32
      | "docusaurus-2"
33
      | "docusaurus"
34
      | "preact"
35
      | "solidstart-1"
36
      | "solidstart"
37
      | "dojo"
38
      | "ember"
39
      | "vue"
40
      | "scully"
41
      | "ionic-angular"
42
      | "angular"
43
      | "polymer"
44
      | "svelte"
45
      | "sveltekit"
46
      | "sveltekit-1"
47
      | "ionic-react"
48
      | "create-react-app"
49
      | "gridsome"
50
      | "umijs"
51
      | "sapper"
52
      | "saber"
53
      | "stencil"
54
      | "nuxtjs"
55
      | "redwoodjs"
56
      | "hugo"
57
      | "jekyll"
58
      | "brunch"
59
      | "middleman"
60
      | "zola"
61
      | "hydrogen"
62
      | "vite"
63
      | "vitepress"
64
      | "vuepress"
65
      | "parcel"
66
      | "fasthtml"
67
      | "sanity-v3"
68
      | "sanity"
69
      | "storybook";
70
    gitForkProtection?: false | true;
71
    gitLFS?: false | true;
72
    installCommand?: string;
73
    name?: string;
74
    nodeVersion?: "22.x" | "20.x" | "18.x" | "16.x" | "14.x" | "12.x" | "10.x";
75
    outputDirectory?: string;
76
    previewDeploymentsDisabled?: false | true;
77
    publicSource?: false | true;
78
    rootDirectory?: string;
79
    serverlessFunctionRegion?: string;
80
    serverlessFunctionZeroConfigFailover?: false | true;
81
    skewProtectionBoundaryAt?: number;
82
    skewProtectionMaxAge?: number;
83
    skipGitConnectDuringLink?: false | true;
84
    sourceFilesOutsideRootDirectory?: false | true;
85
    enablePreviewFeedback?: false | true;
86
    enableProductionFeedback?: false | true;
87
    enableAffectedProjectsDeployments?: false | true;
88
    oidcTokenConfig?: { enabled: false | true; issuerMode?: "team" | "global" };
89
    passwordProtection?: {
90
      deploymentType:
91
        | "all"
92
        | "preview"
93
        | "prod_deployment_urls_and_all_previews";
94
      password?: string;
95
    };
96
    ssoProtection?: {
97
      deploymentType:
98
        | "all"
99
        | "preview"
100
        | "prod_deployment_urls_and_all_previews";
101
    };
102
    trustedIps?: {
103
      deploymentType:
104
        | "all"
105
        | "preview"
106
        | "prod_deployment_urls_and_all_previews"
107
        | "production";
108
      addresses: { value: string; note?: string }[];
109
      protectionMode: "exclusive" | "additional";
110
    };
111
    optionsAllowlist?: { paths: { value: string }[] };
112
  },
113
) {
114
  const url = new URL(`https://api.vercel.com/v9/projects/${idOrName}`);
115
  for (const [k, v] of [
116
    ["teamId", teamId],
117
    ["slug", slug],
118
  ]) {
119
    if (v !== undefined && v !== "" && k !== undefined) {
120
      url.searchParams.append(k, v);
121
    }
122
  }
123
  const response = await fetch(url, {
124
    method: "PATCH",
125
    headers: {
126
      "Content-Type": "application/json",
127
      Authorization: "Bearer " + auth.token,
128
    },
129
    body: JSON.stringify(body),
130
  });
131
  if (!response.ok) {
132
    const text = await response.text();
133
    throw new Error(`${response.status} ${text}`);
134
  }
135
  return await response.json();
136
}
137