Twilio - ERROR 21211 - Invalid 'To' Phone Number for M2M SIM card

Viewed 1009

Is there a possibility to send SMS to an M2M number (in my case consisting of country code plus 13 digits) using Twilio?

I tried using curl:

curl -XPOST https://api.twilio.com/2010-04-01/Accounts/{AccountSID}/Messages.json -d "Body=test" -d "To=%2Bxx xxxxxxxxxxxxx" -d "From=%2Bxx xxxxxxxxxxx" -u "{AccountSID}:{authToken}"

And the result is

{"code": 21211, "message": "The 'To' number +xxxxxxxxxxxxxxx is not a valid phone number.", "more_info": "https://www.twilio.com/docs/errors/21211", "status": 400}

The number is definitely valid, since I can send SMS e.g. from my phone to this number.

When I remove the last three digits of the longer number, I do not get any error.

1 Answers

You need to create the From/Sender number before using the API. Use this link on Twilio console to create your From Number.

Remember to use the number on format E.164 standard

curl --location --request POST 'https://api.twilio.com/2010-04-01/Accounts/ACxxx/Messages.json' \
--header 'Authorization: Basic xxx==' \
--header 'Content-Type: application/x-www-form-urlencoded' \
--data-urlencode 'Body=lalala' \
--data-urlencode 'From=+1205850xxxx' \
--data-urlencode 'To=+55119756xxxxx'
Related