0

Creates a new Integration Log Drain

by
Published Apr 8, 2025

Creates an Integration log drain. This endpoint must be called with an OAuth2 client (integration), since log drains are tied to integrations. If it is called with a different token type 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 Integration Log Drain
7
 * Creates an Integration log drain. This endpoint must be called with an OAuth2 client (integration), since log drains are tied to integrations. If it is called with a different token type it will produce a 400 error.
8
 */
9
export async function main(
10
  auth: Vercel,
11
  teamId: string | undefined,
12
  slug: string | undefined,
13
  body: {
14
    name: string;
15
    projectIds?: string[];
16
    secret?: string;
17
    deliveryFormat?: "json" | "ndjson" | "syslog";
18
    url: string;
19
    sources?:
20
      | "static"
21
      | "lambda"
22
      | "build"
23
      | "edge"
24
      | "external"
25
      | "firewall"[];
26
    headers?: {};
27
    environments?: "preview" | "production"[];
28
  },
29
) {
30
  const url = new URL(`https://api.vercel.com/v2/integrations/log-drains`);
31
  for (const [k, v] of [
32
    ["teamId", teamId],
33
    ["slug", slug],
34
  ]) {
35
    if (v !== undefined && v !== "" && k !== undefined) {
36
      url.searchParams.append(k, v);
37
    }
38
  }
39
  const response = await fetch(url, {
40
    method: "POST",
41
    headers: {
42
      "Content-Type": "application/json",
43
      Authorization: "Bearer " + auth.token,
44
    },
45
    body: JSON.stringify(body),
46
  });
47
  if (!response.ok) {
48
    const text = await response.text();
49
    throw new Error(`${response.status} ${text}`);
50
  }
51
  return await response.json();
52
}
53