pterowraptyl
    Preparing search index...

    Class UsersModule

    Index

    Constructors

    Methods

    • Parameters

      • data: UserRequest

        UserRequest containing user details to create a new user. The email, username, first_name, and last_name fields are required. The password field is optional but recommended. If external_id is provided, it will be used as the user's external identifier. The root_admin field is optional and defaults to false.

      Returns Promise<UserAttributes>

      • A promise that resolves to the created user's attributes.
      const newUser = await ptero.users.createUser({
      username: "ExampleUser",
      email: "example@example.com",
      first_name: "Example",
      last_name: "Example",
      password: "Example123*",
      external_id: "ExampleExternalID",
      root_admin: false,
      });
      console.log("New User Created:", newUser);
    • Deletes a user by their ID. This method will permanently remove the user from the system. *

      Parameters

      • data: UserIdRequest

        UserIdRequest containing the id of the user to delete. If the id is not provided, an error will be thrown.

      Returns Promise<boolean>

      • A promise that resolves to true if the user was successfully deleted. If the user could not be deleted, it will throw an error.
      const deletedUser = await ptero.users.deleteUser({ id: "7" });
      console.log("Deleted User:", deletedUser);
    • Fetches all users with optional sorting, filtering, and pagination.

      Parameters

      • Optionalsort: SortParameters

        Sorting parameters to apply to the results. Allowed values are SortParameters.ID and SortParameters.UUID. If not provided, no sorting is applied.

      • Optionalinclude: IncludeParameters[]

        Include parameters to specify related resources to include in the response. Allowed values are IncludeParameters.SERVERS. If not provided, no related resources are included.

      • Optionalfilter: Record<FilterParameters, string>

        Filter parameters to apply to the results. Allowed values are FilterParameters.EMAIL, FilterParameters.EXTERNAL_ID, FilterParameters.USERNAME, and FilterParameters.UUID. If not provided, no filtering is applied.

      • Optionalpagination: PaginationOptions

        Pagination options to control the number of results returned. If not provided, all results are returned.

      Returns Promise<UserAttributes[]>

      • A promise that resolves to an array of user attributes.
      const users = await ptero.users.fetchAll(
      "id", // sorting field
      ["servers"], // include field
      { uuid: "30591422-fa31-4991-9265-28a30fb033c4", username: "rudo" }, // using available filters
      { page: 1, per_page: 2 } // pagination options
      );
      console.log(users);
    • Parameters

      • data: UserIdRequest

        UserIdRequest containing either id or external_id of the user to fetch. If both are provided, id will be used. If neither is provided, an error will be thrown.

      • Optionalinclude: IncludeParameters[]

        Include parameters to specify related resources to include in the response. Allowed values are IncludeParameters.SERVERS. If not provided, no related resources are included.

      Returns Promise<UserAttributes>

      const user = await ptero.users.fetchOne({ id: 1 });
      console.log(user);

      const userWithExternalId = await ptero.users.fetchOne({ external_id: "remoteId1" });
      console.log(userWithExternalId);
      @returns {Promise<UserAttributes>} - A promise that resolves to the user attributes
    • Updates a user's information using the provided user data.

      Parameters

      • data: UserUpdateRequest

        UserUpdateRequest containing the user's id and the fields to update.

      Returns Promise<UserAttributes>

      • A promise that resolves to the updated user's attributes. If the user could not be updated, it will throw an error.
      const updateUser = await ptero.users.updateUser({
      id: 1,
      username: "new_username",
      email: "example@example.com",
      first_name: "new_first_name",
      last_name: "new_last_name",
      });
      console.log("Update User:", updateUser);