getUsers method

Future<List<MmUser>?> getUsers({
  1. int? page,
  2. int? perPage,
  3. String? inTeam,
  4. String? notInTeam,
  5. String? inChannel,
  6. String? notInChannel,
  7. String? inGroup,
  8. bool? groupConstrained,
  9. bool? withoutTeam,
  10. bool? active,
  11. bool? inactive,
  12. String? role,
  13. String? sort,
  14. String? roles,
  15. String? channelRoles,
  16. String? teamRoles,
})

Get users

Get a page of a list of users. Based on query string parameters, select users from a team, channel, or select users not in a specific channel. Since server version 4.0, some basic sorting is available using the sort query parameter. Sorting is currently only supported when selecting users on a team. ##### Permissions Requires an active session and (if specified) membership to the channel or team being selected from.

Parameters:

  • int page: The page to select.

  • int perPage: The number of users per page. There is a maximum limit of 200 users per page.

  • String inTeam: The ID of the team to get users for.

  • String notInTeam: The ID of the team to exclude users for. Must not be used with "in_team" query parameter.

  • String inChannel: The ID of the channel to get users for.

  • String notInChannel: The ID of the channel to exclude users for. Must be used with "in_channel" query parameter.

  • String inGroup: The ID of the group to get users for. Must have manage_system permission.

  • bool groupConstrained: When used with not_in_channel or not_in_team, returns only the users that are allowed to join the channel or team based on its group constrains.

  • bool withoutTeam: Whether or not to list users that are not on any team. This option takes precendence over in_team, in_channel, and not_in_channel.

  • bool active: Whether or not to list only users that are active. This option cannot be used along with the inactive option.

  • bool inactive: Whether or not to list only users that are deactivated. This option cannot be used along with the active option.

  • String role: Returns users that have this role.

  • String sort: Sort is only available in conjunction with certain options below. The paging parameter is also always available. ##### in_team Can be "", "last_activity_at" or "create_at". When left blank, sorting is done by username. Minimum server version: 4.0 ##### in_channel Can be "", "status". When left blank, sorting is done by username. status will sort by User's current status (Online, Away, DND, Offline), then by Username. Minimum server version: 4.7

  • String roles: Comma separated string used to filter users based on any of the specified system roles Example: ?roles=system_admin,system_user will return users that are either system admins or system users Minimum server version: 5.26

  • String channelRoles: Comma separated string used to filter users based on any of the specified channel roles, can only be used in conjunction with in_channel Example: ?in_channel=4eb6axxw7fg3je5iyasnfudc5y&channel_roles=channel_user will return users that are only channel users and not admins or guests Minimum server version: 5.26

  • String teamRoles: Comma separated string used to filter users based on any of the specified team roles, can only be used in conjunction with in_team Example: ?in_team=4eb6axxw7fg3je5iyasnfudc5y&team_roles=team_user will return users that are only team users and not admins or guests Minimum server version: 5.26

Implementation

Future<List<MmUser>?> getUsers({
  int? page,
  int? perPage,
  String? inTeam,
  String? notInTeam,
  String? inChannel,
  String? notInChannel,
  String? inGroup,
  bool? groupConstrained,
  bool? withoutTeam,
  bool? active,
  bool? inactive,
  String? role,
  String? sort,
  String? roles,
  String? channelRoles,
  String? teamRoles,
}) async {
  final response = await getUsersWithHttpInfo(
    page: page,
    perPage: perPage,
    inTeam: inTeam,
    notInTeam: notInTeam,
    inChannel: inChannel,
    notInChannel: notInChannel,
    inGroup: inGroup,
    groupConstrained: groupConstrained,
    withoutTeam: withoutTeam,
    active: active,
    inactive: inactive,
    role: role,
    sort: sort,
    roles: roles,
    channelRoles: channelRoles,
    teamRoles: teamRoles,
  );
  if (response.statusCode >= HttpStatus.badRequest) {
    throw MmApiException(response.statusCode, await _decodeBodyBytes(response));
  }
  // When a remote server returns no body with a status of 204, we shall not decode it.
  // At the time of writing this, `dart:convert` will throw an "Unexpected end of input"
  // FormatException when trying to decode an empty string.
  if (response.body.isNotEmpty && response.statusCode != HttpStatus.noContent) {
    final responseBody = await _decodeBodyBytes(response);
    return (await apiClient.deserializeAsync(responseBody, 'List<MmUser>') as List).cast<MmUser>().toList();
  }
  return null;
}