I am trying to use AWS SNS's optInPhoneNumber
function. But I am getting this error.
InvalidParameter: Invalid parameter:
at Request.extractError
at Request.callListeners
at Request.emit
at Request.emit
at Request.transition
at AcceptorStateMachine.runTo
at
at Request.<anonymous>
at Request.<anonymous>
at Request.callListeners
at Request.emit
at Request.emit
at Request.transition
at AcceptorStateMachine.runTo
at Request.<anonymous>
at Request.<anonymous>
....
code: 'InvalidParameter',
time: 2021-07-30T17:28:08.847Z,
requestId: '23aa0a5d-7875-5438-b051-5323409d09f4',
statusCode: 400,
retryable: false,
retryDelay: 4.786451228396071
Here is my Code. Don't worry about the return statement. Just to satisfy the front-end I am passing a hardcoded value.
import AWS from 'aws-sdk';
import { parsePhoneNumber } from 'libphonenumber-js';
export const optInPhoneNumber = async (phoneNumber: string) => {
const client = new AWS.SNS({region: 'us-east-1'});
const params = {
phoneNumber: parsePhoneNumber(phoneNumber, 'US')?.format('E.164'),
};
client
.optInPhoneNumber(params)
.promise()
.then(data => {
console.log(data);
})
.catch(error => {
console.log(error);
});
return {
isError: false,
};
};
EDIT: the passing phoneNumber:647-XXX-XXXX
. But when I pass phoneNumber as 647-XXX-XXX is passes, which is not a valid number.
Any help would be appreciated
I figured out that I opted out a number and was trying to re opt-in. But in the docs, it says that you can opt for a number every 30 days