0

Creates a Configurable Log Drain

by
Published Apr 8, 2025

Creates a configurable log drain. This endpoint must be called with a team AccessToken (integration OAuth2 clients are not allowed)

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 Configurable Log Drain
7
 * Creates a configurable log drain. This endpoint must be called with a team AccessToken (integration OAuth2 clients are not allowed)
8
 */
9
export async function main(
10
  auth: Vercel,
11
  teamId: string | undefined,
12
  slug: string | undefined,
13
  body: {
14
    deliveryFormat: "json" | "ndjson";
15
    url: string;
16
    headers?: {};
17
    projectIds?: string[];
18
    sources: "static" | "lambda" | "build" | "edge" | "external" | "firewall"[];
19
    environments?: "preview" | "production"[];
20
    secret?: string;
21
    samplingRate?: number;
22
    name?: string;
23
  },
24
) {
25
  const url = new URL(`https://api.vercel.com/v1/log-drains`);
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