[RestException [Error]: The 'To' number 9977428080 is not a valid phone number
Asked Answered
K

3

7

I am trying to send sms to number using Twilio API's, but I am getting error like [RestException [Error]: The 'To' number 9977428080 is not a valid phone number.] { status: 400, message: "The 'To' number 9977428080 is not a valid phone number.", code: 21211, moreInfo: 'https://www.twilio.com/docs/errors/21211', detail: undefined }

before this I was getting the from number is not valid then I switched my API's credentials testing to Live credentials, the I got this another issue. These are the code below

const client = require('twilio')(config.SId, config.AccesToekn);
// SEND OTP TO USER ACCOUNT
router.post('/sendsms',(req, res, next)=>{
client.messages.create({
     from:'+15204770942',
     to:"9977428080",
     body:'Please user this OPT to verify your number 74536',
 }, function(error, data){
     if(error){
   console.log(error,'error')
    console.log(data,"data")
     }
 })
})

and My credential are correct. What might be cause of occurring this issue, any your help would be highly appreciated

Thanks in Advance

Kubiak answered 27/10, 2019 at 15:58 Comment(0)
S
3

error.moreInfo: 'https://www.twilio.com/docs/errors/21211'

Twilio accepts phone numbers in E164 format: [+] [country code] [subscriber number including area code]

Further on the format:

What is E.164?

Example: +14155552671

change to:

const client = require('twilio')(config.SId, config.AccesToekn);
// SEND OTP TO USER ACCOUNT
router.post('/sendsms',(req, res, next)=>{
client.messages.create({
     from:'+15204770942', 
     to:"+9199778080", //this must be a verified phone number for twilio trial accounts
     body:'Please user this OPT to verify your number 74536',
 }, function(error, data){
     if(error){
   console.log(error,'error')
    console.log(data,"data")
     }
 })
})
Skinned answered 27/10, 2019 at 16:58 Comment(9)
Thanks for the reply I have changed as per the my country code like +919568172162 as I am from India but it giving me error like[RestException [Error]: The number is unverified. Trial accounts cannot send messages to unverified numbers; verify at twilio.com/user/account/phone-numbers/verified, or purchase a Twilio number to send messages to unverified numbers.] {Kubiak
I think this would be better as a new question, however, Twilio does not allow you to use unverified phone numbers in their trial accounts (to avoid spam and force you to upgrade your account among other things) Here's how to verify phone numberSkinned
That I can understand it does not allow unverified number but the one number I have which is verified and registered with the my tiwilo account as well. so it it verified then it should be accept .Kubiak
for trial accounts both numbers must be verified. +15204770942 and +19977428080 you need to see both numbers listed hereSkinned
yes +9199778080 is listed but this one is not +15204770942 showing it is twilio numberKubiak
+9199778080 does not match your code which is (per your comment above) +919568172162 or from the code snippet you posted +919977428080 (all are different)Skinned
yes I pasted both different but this is verified +9199778080 and If I am using it nothing happening no response and no errorKubiak
even though trail account should send sms but I don't what is going wrong hereKubiak
I'm glad we got you to this point! However I think it's best to mark this question as answered, do some trouble shooting and ask a new question as this is likely a completely different issue now. It's just really hard to answer questions of this magnitude in the comments section (: cheers!Skinned
L
2

Got Same Issue. But, Here we need to just add country code.

            var message = MessageResource.Create(
                body: "Order Placed on BulkyBook. Your Order ID:" + id,
                from: new Twilio.Types.PhoneNumber(_twilloOptions.PhoneNumber),
                to: new Twilio.Types.PhoneNumber("+91" + orderHeader.PhoneNumber)
                );
        
Laddie answered 26/7, 2021 at 16:36 Comment(1)
Please provide a detailed explanation to your answer, in order for the next user to understand your answer better.Georgiageorgian
C
1

when use use Twilio then always use country code with phone number

Choreography answered 27/7, 2021 at 4:27 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.