Bad request (400) when trying to set phone_number to cognito account

0

Hello, I have a little problem with setting phone_number to newly created AWS cognito accounts. When I try to register a new user via

const command = new AdminCreateUserCommand({
       Username: userToCreate.email,
       UserAttributes: [
         {
           Name: CognitoProperties.PHONE_NUMBER,
           Value: `${userToCreate.phoneNumber}`,
         },
         {
           Name: CognitoProperties.EMAIL,
           Value: `${userToCreate.email}`,
         },
         {
           Name: CognitoProperties.FULL_NAME,
           Value: `${userToCreate.fullName}`,
         },
       ],

       UserPoolId: this.configService.get('AWS_COGNITO_USER_POOL_ID'),
     });
     const commandResult = await this.AWS_CLIENT.send(command);

I got the following error:

"name": "InvalidParameterException",
     "$fault": "client",
     "$metadata": {
       "httpStatusCode": 400,
       "requestId": "---REQUEST_ID----",
       "attempts": 1,
       "totalRetryDelay": 0
},
"__type": "InvalidParameterException"

I have tried multiple number formats, including the phone number provided in AWS Cognito documentation (+14325551212). Also, I have tried removing property phone_number from my request, which removed the error. The same error occurred when I tried to register a user with postman client. The interesting part is that even though cognito returns 400 error it still saves the user. Can you please suggest what am I doing wrong and help me fix that?

asked 7 months ago76 views
No Answers

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.

Guidelines for Answering Questions