Edits history of script submission #14361 for ' Create user (box)'

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