Edits history of script submission #13716 for ' Create Event (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Create Event
     * Partner notifies Vercel of any changes made to an Installation or a Resource.
     */
    export async function main(
      auth: Vercel,
      integrationConfigurationId: string,
      body: {
        event:
          | { type: "installation.updated"; billingPlanId?: string }
          | { type: "resource.updated"; productId: string; resourceId: string };
      },
    ) {
      const url = new URL(
        `https://api.vercel.com/v1/installations/${integrationConfigurationId}/events`,
      );
    
      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