listUsers method
Lists the users in the Amazon Cognito user pool.
May throw InvalidParameterException. May throw ResourceNotFoundException. May throw TooManyRequestsException. May throw NotAuthorizedException. May throw InternalErrorException.
Parameter userPoolId
:
The user pool ID for the user pool on which the search should be
performed.
Parameter attributesToGet
:
An array of strings, where each string is the name of a user attribute to
be returned for each user in the search results. If the array is null, all
attributes are returned.
Parameter filter
:
A filter string of the form "AttributeName Filter-Type
"AttributeValue"". Quotation marks within the filter string must be
escaped using the backslash () 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.
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
For more information, see Searching for Users Using the ListUsers API and Examples of Using the ListUsers API in the Amazon Cognito Developer Guide.
Parameter limit
:
Maximum number of users to be returned.
Parameter paginationToken
:
An identifier that was returned from the previous call to this operation,
which can be used to return the next set of items in the list.
Implementation
Future<ListUsersResponse> listUsers({
required String userPoolId,
List<String>? attributesToGet,
String? filter,
int? limit,
String? paginationToken,
}) async {
ArgumentError.checkNotNull(userPoolId, 'userPoolId');
_s.validateStringLength(
'userPoolId',
userPoolId,
1,
55,
isRequired: true,
);
_s.validateStringLength(
'filter',
filter,
0,
256,
);
_s.validateNumRange(
'limit',
limit,
0,
60,
);
_s.validateStringLength(
'paginationToken',
paginationToken,
1,
1152921504606846976,
);
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);
}