Edits history of script submission #13729 for ' Create one or multiple experimentation items (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Create one or multiple experimentation items
     * Create one or multiple experimentation items
     */
    export async function main(
      auth: Vercel,
      integrationConfigurationId: string,
      resourceId: string,
      body: {
        items: {
          id: string;
          slug: string;
          origin: string;
          category?: "experiment" | "flag";
          name?: string;
          description?: string;
          isArchived?: false | true;
          createdAt?: number;
          updatedAt?: number;
        }[];
      },
    ) {
      const url = new URL(
        `https://api.vercel.com/v1/installations/${integrationConfigurationId}/resources/${resourceId}/experimentation/items`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        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