Edits history of script submission #11955 for ' Bulk create and send organization invitations (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Bulk create and send organization invitations
     * Creates new organization invitations in bulk and sends out emails to the provided email addresses with a link to accept the invitation and join the organization.
     */
    export async function main(
      auth: Clerk,
      organization_id: string,
      body: {
        email_address: string;
        inviter_user_id?: string;
        role: string;
        public_metadata?: {};
        private_metadata?: {};
        redirect_url?: string;
      }[],
    ) {
      const url = new URL(
        `https://api.clerk.com/v1/organizations/${organization_id}/invitations/bulk`,
      );
    
      const response = await fetch(url, {
        method: "POST",
        headers: {
          "Content-Type": "application/json",
          Authorization: "Bearer " + auth.apiKey,
        },
        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