Edits history of script submission #14562 for ' Update user (box)'

  • bun
    One script reply has been approved by the moderators
    Ap­pro­ved
    //native
    type Box = {
      token: string;
    };
    /**
     * Update user
     * Updates a managed or app user in an enterprise. This endpoint
    is only available to users and applications with the right
    admin permissions.
     */
    export async function main(
      auth: Box,
      user_id: string,
      fields: string | undefined,
      body: {
        enterprise?: string;
        notify?: false | true;
        name?: string;
        login?: string;
        role?: "coadmin" | "user";
        language?: string;
        is_sync_enabled?: false | true;
        job_title?: string;
        phone?: string;
        address?: string;
        tracking_codes?: {
          type?: "tracking_code";
          name?: string;
          value?: string;
        }[];
        can_see_managed_users?: false | true;
        timezone?: string;
        is_external_collab_restricted?: false | true;
        is_exempt_from_device_limits?: false | true;
        is_exempt_from_login_verification?: false | true;
        is_password_reset_required?: false | true;
        status?:
          | "active"
          | "inactive"
          | "cannot_delete_edit"
          | "cannot_delete_edit_upload";
        space_amount?: number;
        notification_email?: { email?: string };
        external_app_user_id?: string;
      },
    ) {
      const url = new URL(`https://api.box.com/2.0/users/${user_id}`);
      for (const [k, v] of [["fields", fields]]) {
        if (v !== undefined && v !== "" && k !== undefined) {
          url.searchParams.append(k, v);
        }
      }
      const response = await fetch(url, {
        method: "PUT",
        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 235 days ago