- Navigation GuideYou are on a Command (operation) page with structural examples. Use the navigation breadcrumb if you would like to return to the Client landing page.
ListUsersCommand
Given a user pool ID, returns a list of users and their basic details in a user pool.
Amazon Cognito evaluates Identity and Access Management (IAM) policies in requests for this API operation. For this operation, you must use IAM credentials to authorize requests, and you must grant yourself the corresponding IAM permission in a policy.
Learn more
Example Syntax
Use a bare-bones client and the command you need to make an API call.
import { CognitoIdentityProviderClient, ListUsersCommand } from "@aws-sdk/client-cognito-identity-provider"; // ES Modules import
// const { CognitoIdentityProviderClient, ListUsersCommand } = require("@aws-sdk/client-cognito-identity-provider"); // CommonJS import
const client = new CognitoIdentityProviderClient(config);
const input = { // ListUsersRequest
UserPoolId: "STRING_VALUE", // required
AttributesToGet: [ // SearchedAttributeNamesListType
"STRING_VALUE",
],
Limit: Number("int"),
PaginationToken: "STRING_VALUE",
Filter: "STRING_VALUE",
};
const command = new ListUsersCommand(input);
const response = await client.send(command);
// { // ListUsersResponse
// Users: [ // UsersListType
// { // UserType
// Username: "STRING_VALUE",
// Attributes: [ // AttributeListType
// { // AttributeType
// Name: "STRING_VALUE", // required
// Value: "STRING_VALUE",
// },
// ],
// UserCreateDate: new Date("TIMESTAMP"),
// UserLastModifiedDate: new Date("TIMESTAMP"),
// Enabled: true || false,
// UserStatus: "UNCONFIRMED" || "CONFIRMED" || "ARCHIVED" || "COMPROMISED" || "UNKNOWN" || "RESET_REQUIRED" || "FORCE_CHANGE_PASSWORD" || "EXTERNAL_PROVIDER",
// MFAOptions: [ // MFAOptionListType
// { // MFAOptionType
// DeliveryMedium: "SMS" || "EMAIL",
// AttributeName: "STRING_VALUE",
// },
// ],
// },
// ],
// PaginationToken: "STRING_VALUE",
// };
Example Usage
ListUsersCommand Input
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
UserPoolId Required | string | undefined | The ID of the user pool where you want to display or search for users. |
AttributesToGet | string[] | undefined | A JSON array of user attribute names, for example Use |
Filter | string | undefined | A filter string of the form
If the filter string is empty, You can only search for the following standard attributes:
Custom attributes aren't searchable. You can also list users with a client-side filter. The server-side filter matches no more than one attribute. For an advanced search, use a client-side filter with the For more information about server-side and client-side filtering, see FilteringCLI output in the Command Line Interface User Guide . For more information, see Searching for Users Using the ListUsers API and Examples of Using the ListUsers API in the Amazon Cognito Developer Guide. |
Limit | number | undefined | The maximum number of users that you want Amazon Cognito to return in the response. |
PaginationToken | string | undefined | This API operation returns a limited number of results. The pagination token is an identifier that you can present in an additional API request with the same parameters. When you include the pagination token, Amazon Cognito returns the next set of items after the current list. Subsequent requests return a new pagination token. By use of this token, you can paginate through the full list of items. |
ListUsersCommand Output
Parameter | Type | Description |
---|
Parameter | Type | Description |
---|---|---|
$metadata Required | ResponseMetadata | Metadata pertaining to this request. |
PaginationToken | string | undefined | The identifier that Amazon Cognito returned with the previous request to this operation. When you include a pagination token in your request, Amazon Cognito returns the next set of items in the list. By use of this token, you can paginate through the full list of items. |
Users | UserType[] | undefined | An array of user pool users who match your query, and their attributes. |
Throws
Name | Fault | Details |
---|
Name | Fault | Details |
---|---|---|
InternalErrorException | server | This exception is thrown when Amazon Cognito encounters an internal error. |
InvalidParameterException | client | This exception is thrown when the Amazon Cognito service encounters an invalid parameter. |
NotAuthorizedException | client | This exception is thrown when a user isn't authorized. |
ResourceNotFoundException | client | This exception is thrown when the Amazon Cognito service can't find the requested resource. |
TooManyRequestsException | client | This exception is thrown when the user has made too many requests for a given operation. |
CognitoIdentityProviderServiceException | Base exception class for all service exceptions from CognitoIdentityProvider service. |