Edits history of script submission #13791 for ' Invite a user (vercel)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Vercel = {
      token: string;
    };
    /**
     * Invite a user
     * Invite a user to join the team specified in the URL. The authenticated user needs to be an `OWNER` in order to successfully invoke this endpoint. The user can be specified with an email or an ID. If both email and ID are provided, ID will take priority.
     */
    export async function main(
      auth: Vercel,
      teamId: string,
      body: {
        uid?: string;
        email?: string;
        role?:
          | "OWNER"
          | "MEMBER"
          | "DEVELOPER"
          | "SECURITY"
          | "BILLING"
          | "VIEWER"
          | "CONTRIBUTOR";
        projects?: {
          projectId: string;
          role: "ADMIN" | "PROJECT_VIEWER" | "PROJECT_DEVELOPER";
        }[];
      },
    ) {
      const url = new URL(`https://api.vercel.com/v1/teams/${teamId}/members`);
    
      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.json();
    }
    

    Submitted by hugo697 428 days ago