Edits history of script submission #13812 for ' Patch an existing experimentation item (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Patch an existing experimentation item
     * Patch an existing experimentation item
     */
    export async function main(
      auth: Vercel,
      integrationConfigurationId: string,
      resourceId: string,
      itemId: string,
      body: {
        slug: string;
        origin: string;
        name?: string;
        category?: "experiment" | "flag";
        description?: string;
        isArchived?: false | true;
        createdAt?: number;
        updatedAt?: number;
      },
    ) {
      const url = new URL(
        `https://api.vercel.com/v1/installations/${integrationConfigurationId}/resources/${resourceId}/experimentation/items/${itemId}`,
      );
    
      const response = await fetch(url, {
        method: "PATCH",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.token,
        },
        body: JSON.stringify(body),
      });
      if (!response.ok) {
        const text = await response.text();
        throw new Error(`${response.status} ${text}`);
      }
      return await response.text();
    }
    

    Submitted by hugo697 428 days ago