Edits history of script submission #12060 for ' Update a user (clerk)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Clerk = {
      apiKey: string;
    };
    /**
     * Update a user
     * Update a user's attributes.
     */
    export async function main(
      auth: Clerk,
      user_id: string,
      body: {
        external_id?: string;
        first_name?: string;
        last_name?: string;
        primary_email_address_id?: string;
        notify_primary_email_address_changed?: false | true;
        primary_phone_number_id?: string;
        primary_web3_wallet_id?: string;
        username?: string;
        profile_image_id?: string;
        password?: string;
        password_digest?: string;
        password_hasher?: string;
        skip_password_checks?: false | true;
        sign_out_of_other_sessions?: false | true;
        totp_secret?: string;
        backup_codes?: string[];
        public_metadata?: {};
        private_metadata?: {};
        unsafe_metadata?: {};
        delete_self_enabled?: false | true;
        create_organization_enabled?: false | true;
        legal_accepted_at?: string;
        skip_legal_checks?: false | true;
        create_organizations_limit?: number;
        created_at?: string;
      },
    ) {
      const url = new URL(`https://api.clerk.com/v1/users/${user_id}`);
    
      const response = await fetch(url, {
        method: "PATCH",
        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