Test credentials and magic phone numbers are used to test applications without actually sending SMS messages or making actual voice phone calls. These tools save time and money because you’re not charged for testing and responses are quicker as the tests only communicate with Twilio service, i.e. tests stay within Twilio services, no connections are made to carriers.
To follow along, if you are using UNIX or a Mac computer, use cURL to send SMS messages. If you are using Windows, you will need to write a program as outlined in our Send SMS Messages documentation. Here is the cURL command from the documentation:
curl -X POST 'https://api.twilio.com/2010-04-01/Accounts/ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX/Messages.json'
—data-urlencode 'To=+16501231234'
—data-urlencode 'From=+16502223333'
—data-urlencode 'Body=Hello there'
-u ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX:your_auth_token
Replace 16501231234
with your mobile phone number, and replace 16502223333
with your Twilio phone number. Replace ACXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX
with your Account SID, and replace your_auth_token
with your Twilio account auth token, both of which can be found on your Twilio Console dashboard.
When you run the above curl command using your account information, you will receive an SMS message, “Hello there,” on your phone from your Twilio phone number, 16502223333
.
Next, change your account SID and auth token to your test account SID and auth token. You will find your test account credentials (SID and auth token) on the Console Settings page in your Master account. When you run the cURL command you will get the error:
--- com.twilio.exception.ApiException: The From phone number +16502223333 is not a valid.
It is invalid because test account credentials don’t have access to Twilio account phone numbers.
Change your sender phone number to the magic phone number: +15005550006
. Running the command again, using your test credentials with the magic phone number, it is successful. You will not receive an SMS on your phone because there is no actual sending of an SMS when using test account credentials.
The Test Credentials documentation page has a table of magic phone numbers, each of which generates a specific error message, or is valid and doesn’t generate an error. For example, the magic phone number, +15005550001
, will generate an invalid phone number error. In the documentation page, search for “phone number is unavailable” and you will see one of the tables. Scroll down to view the other tables of magic phone numbers. Here is a documentation sample table:
Magic Phone Number | Description | Error Code |
+15005550000 | This phone number is unavailable. | 21422 |
+15005550001 | This phone number is invalid. | 21421 |
+15005550006 | This phone number is valid and available. | No error |
Now you’re ready to use your test credentials with a list of magic numbers to test your application’s logic paths. This will speed up your testing while improving your program’s reliability, and ability, to report on errors and successes.