When encountering Error 21211 in your Twilio integration, it typically indicates an issue with the To number provided in your API request. Below, we outline the possible causes and solutions to resolve this error effectively.
Possible Causes
Invalid Formatting of the To Number
The To number supplied is not formatted correctly.
Twilio Number Used for Both To and From
You attempted to send a message or place a call from a Twilio number to itself by using the same number for the To and From parameters.
Sending to a Short Code
The To number provided corresponds to a Short Code, which cannot accept messages from Twilio numbers.
Sending to an Alphanumeric Sender ID
You attempted to send a message to an Alphanumeric Sender ID, which does not support receiving messages.
Invalid Prefix in the To Number
When using a Messaging Service, the To number contains an invalid prefix.
Possible Solutions
Format Numbers in E.164
Ensure all phone numbers are formatted in E.164 format:
[+] [country code] [subscriber number including area code]
Example:
+14155552671
.
Verify Country Calling Codes
Double-check that you’ve used the correct country calling code for the destination number.
Avoid Calling or Messaging Twilio Numbers from Themselves
Ensure the To and From parameters in your request do not reference the same Twilio number.
Avoid Sending to Short Codes or Alphanumeric Sender IDs
Messages to Short Codes or Alphanumeric Sender IDs cannot be sent from Twilio numbers.
Check for Typos or Input Errors
Review the To number for any typos or incorrect input methods.
Test API Requests in Twilio Console
Use the "Try it out" feature in the Twilio console to test your API request. If this test succeeds, check any third-party integrations for unexpected changes to the To parameter.
Correct Invalid Prefixes When Using Messaging Services
Instead of using an invalid prefix, remove it and send directly to the To number in E.164 format. Example:
[+] [country code] [subscriber number including area code]
If the To number accepts RCS messages and an RCS Agent is available in the Messaging Service Sender Pool, it will be selected automatically.
Following these steps should help you resolve Error 21211 and ensure smooth operation of your Twilio integration.
For more information, you can refer to this page