Edits history of script submission #11976 for ' Create and send an organization invitation (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Create and send an organization invitation
     * Creates a new organization invitation and sends an email to the provided `email_address` 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`,
      );
    
      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