0

Creates a new Check

by
Published Apr 8, 2025

Creates a new check. This endpoint must be called with an OAuth2 or it will produce a 400 error.

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Creates a new Check
7
 * Creates a new check. This endpoint must be called with an OAuth2 or it will produce a 400 error.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  deploymentId: string,
12
  teamId: string | undefined,
13
  slug: string | undefined,
14
  body: {
15
    name: string;
16
    path?: string;
17
    blocking: false | true;
18
    detailsUrl?: string;
19
    externalId?: string;
20
    rerequestable?: false | true;
21
  },
22
) {
23
  const url = new URL(
24
    `https://api.vercel.com/v1/deployments/${deploymentId}/checks`,
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: "POST",
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