0

Create one or multiple experimentation items

by
Published Apr 8, 2025

Create one or multiple experimentation items

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 one or multiple experimentation items
7
 * Create one or multiple experimentation items
8
 */
9
export async function main(
10
  auth: Vercel,
11
  integrationConfigurationId: string,
12
  resourceId: string,
13
  body: {
14
    items: {
15
      id: string;
16
      slug: string;
17
      origin: string;
18
      category?: "experiment" | "flag";
19
      name?: string;
20
      description?: string;
21
      isArchived?: false | true;
22
      createdAt?: number;
23
      updatedAt?: number;
24
    }[];
25
  },
26
) {
27
  const url = new URL(
28
    `https://api.vercel.com/v1/installations/${integrationConfigurationId}/resources/${resourceId}/experimentation/items`,
29
  );
30

31
  const response = await fetch(url, {
32
    method: "POST",
33
    headers: {
34
      "Content-Type": "application/json",
35
      Authorization: "Bearer " + auth.token,
36
    },
37
    body: JSON.stringify(body),
38
  });
39
  if (!response.ok) {
40
    const text = await response.text();
41
    throw new Error(`${response.status} ${text}`);
42
  }
43
  return await response.text();
44
}
45