0

Create a new deployment

by
Published Apr 8, 2025

Create a new deployment with all the required and intended data. If the deployment is not a git deployment, all files must be provided with the request, either referenced or inlined. Additionally, a deployment id can be specified to redeploy a previous deployment.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Create a new deployment
7
 * Create a new deployment with all the required and intended data. If the deployment is not a git deployment, all files must be provided with the request, either referenced or inlined. Additionally, a deployment id can be specified to redeploy a previous deployment.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  forceNew: "0" | "1" | undefined,
12
  skipAutoDetectionConfirmation: "0" | "1" | undefined,
13
  teamId: string | undefined,
14
  slug: string | undefined,
15
  body: {
16
    customEnvironmentSlugOrId?: string;
17
    deploymentId?: string;
18
    files?:
19
      | { data: string; encoding?: "base64" | "utf-8"; file: string }
20
      | { file: string; sha?: string; size?: number }[];
21
    gitMetadata?: {
22
      remoteUrl?: string;
23
      commitAuthorName?: string;
24
      commitMessage?: string;
25
      commitRef?: string;
26
      commitSha?: string;
27
      dirty?: false | true;
28
    };
29
    gitSource?:
30
      | { ref: string; repoId: string | number; sha?: string; type: "github" }
31
      | { org: string; ref: string; repo: string; sha?: string; type: "github" }
32
      | {
33
          projectId: string | number;
34
          ref: string;
35
          sha?: string;
36
          type: "gitlab";
37
        }
38
      | {
39
          ref: string;
40
          repoUuid: string;
41
          sha?: string;
42
          type: "bitbucket";
43
          workspaceUuid?: string;
44
        }
45
      | {
46
          owner: string;
47
          ref: string;
48
          sha?: string;
49
          slug: string;
50
          type: "bitbucket";
51
        };
52
    meta?: {};
53
    monorepoManager?: string;
54
    name: string;
55
    project?: string;
56
    projectSettings?: {
57
      buildCommand?: string;
58
      commandForIgnoringBuildStep?: string;
59
      devCommand?: string;
60
      framework?:
61
        | "blitzjs"
62
        | "nextjs"
63
        | "gatsby"
64
        | "remix"
65
        | "react-router"
66
        | "astro"
67
        | "hexo"
68
        | "eleventy"
69
        | "docusaurus-2"
70
        | "docusaurus"
71
        | "preact"
72
        | "solidstart-1"
73
        | "solidstart"
74
        | "dojo"
75
        | "ember"
76
        | "vue"
77
        | "scully"
78
        | "ionic-angular"
79
        | "angular"
80
        | "polymer"
81
        | "svelte"
82
        | "sveltekit"
83
        | "sveltekit-1"
84
        | "ionic-react"
85
        | "create-react-app"
86
        | "gridsome"
87
        | "umijs"
88
        | "sapper"
89
        | "saber"
90
        | "stencil"
91
        | "nuxtjs"
92
        | "redwoodjs"
93
        | "hugo"
94
        | "jekyll"
95
        | "brunch"
96
        | "middleman"
97
        | "zola"
98
        | "hydrogen"
99
        | "vite"
100
        | "vitepress"
101
        | "vuepress"
102
        | "parcel"
103
        | "fasthtml"
104
        | "sanity-v3"
105
        | "sanity"
106
        | "storybook";
107
      installCommand?: string;
108
      nodeVersion?:
109
        | "22.x"
110
        | "20.x"
111
        | "18.x"
112
        | "16.x"
113
        | "14.x"
114
        | "12.x"
115
        | "10.x"
116
        | "8.10.x";
117
      outputDirectory?: string;
118
      rootDirectory?: string;
119
      serverlessFunctionRegion?: string;
120
      skipGitConnectDuringLink?: false | true;
121
      sourceFilesOutsideRootDirectory?: false | true;
122
    };
123
    target?: string;
124
    withLatestCommit?: false | true;
125
  },
126
) {
127
  const url = new URL(`https://api.vercel.com/v13/deployments`);
128
  for (const [k, v] of [
129
    ["forceNew", forceNew],
130
    ["skipAutoDetectionConfirmation", skipAutoDetectionConfirmation],
131
    ["teamId", teamId],
132
    ["slug", slug],
133
  ]) {
134
    if (v !== undefined && v !== "" && k !== undefined) {
135
      url.searchParams.append(k, v);
136
    }
137
  }
138
  const response = await fetch(url, {
139
    method: "POST",
140
    headers: {
141
      "Content-Type": "application/json",
142
      Authorization: "Bearer " + auth.token,
143
    },
144
    body: JSON.stringify(body),
145
  });
146
  if (!response.ok) {
147
    const text = await response.text();
148
    throw new Error(`${response.status} ${text}`);
149
  }
150
  return await response.json();
151
}
152