0

Patch an existing experimentation item

by
Published Apr 8, 2025

Patch an existing experimentation item

Script vercel Verified

The script

Submitted by hugo697 Bun
Verified 428 days ago
1
//native
2
type Vercel = {
3
  token: string;
4
};
5
/**
6
 * Patch an existing experimentation item
7
 * Patch an existing experimentation item
8
 */
9
export async function main(
10
  auth: Vercel,
11
  integrationConfigurationId: string,
12
  resourceId: string,
13
  itemId: string,
14
  body: {
15
    slug: string;
16
    origin: string;
17
    name?: string;
18
    category?: "experiment" | "flag";
19
    description?: string;
20
    isArchived?: false | true;
21
    createdAt?: number;
22
    updatedAt?: number;
23
  },
24
) {
25
  const url = new URL(
26
    `https://api.vercel.com/v1/installations/${integrationConfigurationId}/resources/${resourceId}/experimentation/items/${itemId}`,
27
  );
28

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