listUsers method

Future<ListUsersResponse> listUsers({
  1. required String userPoolId,
  2. List<String>? attributesToGet,
  3. String? filter,
  4. int? limit,
  5. String? paginationToken,
})

Given a user pool ID, returns a list of users and their basic details in a user pool.

This operation is eventually consistent. You might experience a delay before results are up-to-date. To validate the existence or configuration of an individual user, use AdminGetUser.

Learn more

May throw InternalErrorException. May throw InvalidParameterException. May throw NotAuthorizedException. May throw OperationNotEnabledException. May throw ResourceNotFoundException. May throw TooManyRequestsException.

Parameter userPoolId : The ID of the user pool where you want to display or search for users.

Parameter attributesToGet : A JSON array of user attribute names, for example given_name, that you want Amazon Cognito to include in the response for each user. When you don't provide an AttributesToGet parameter, Amazon Cognito returns all attributes for each user.

Use AttributesToGet with required attributes in your user pool, or in conjunction with Filter. Amazon Cognito returns an error if not all users in the results have set a value for the attribute you request. Attributes that you can't filter on, including custom attributes, must have a value set in every user profile before an AttributesToGet parameter returns results.

Parameter filter : A filter string of the form "AttributeName Filter-Type "AttributeValue". Quotation marks within the filter string must be escaped using the backslash (</code>) character. For example, "family_name = "Reddy"".

  • AttributeName: The name of the attribute to search for. You can only search for one attribute at a time.
  • Filter-Type: For an exact match, use =, for example, "given_name = \"Jon\"". For a prefix ("starts with") match, use ^=, for example, "given_name ^= \"Jon\"".
  • AttributeValue: The attribute value that must be matched for each user.
If the filter string is empty, ListUsers returns all users in the user pool.

You can only search for the following standard attributes:

  • username (case-sensitive)
  • email
  • phone_number
  • name
  • given_name
  • family_name
  • preferred_username
  • cognito:user_status (called Status in the Console) (case-insensitive)
  • status (called Enabled in the Console) (case-sensitive)
  • sub
Custom attributes aren't searchable.

Implementation

Future<ListUsersResponse> listUsers({
  required String userPoolId,
  List<String>? attributesToGet,
  String? filter,
  int? limit,
  String? paginationToken,
}) async {
  _s.validateNumRange(
    'limit',
    limit,
    0,
    60,
  );
  final headers = <String, String>{
    'Content-Type': 'application/x-amz-json-1.1',
    'X-Amz-Target': 'AWSCognitoIdentityProviderService.ListUsers'
  };
  final jsonResponse = await _protocol.send(
    method: 'POST',
    requestUri: '/',
    exceptionFnMap: _exceptionFns,
    // TODO queryParams
    headers: headers,
    payload: {
      'UserPoolId': userPoolId,
      if (attributesToGet != null) 'AttributesToGet': attributesToGet,
      if (filter != null) 'Filter': filter,
      if (limit != null) 'Limit': limit,
      if (paginationToken != null) 'PaginationToken': paginationToken,
    },
  );

  return ListUsersResponse.fromJson(jsonResponse.body);
}