In this guide you will learn the fundamentals to build your first SMS notification app.
This guide covers:
- Getting a free trial number from Twilio
- Sending your first SMS
- A step-by-step tutorial on sending SMS notifications
- Best practices on scaling
Getting a free trial number from Twilio
To send or receive SMS, you will need a phone number from Twilio. On your trial account, you can get one free USA or Canada phone number.
- To get your trial number, access the account dashboard, and then select Get a trial phone number.
- Click Choose this Number.
- Click Done.
To buy more numbers, or get local phone numbers outside of the USA or Canada, you may need to upgrade your account.
Sending your first SMS
Next, copy and execute the following code in your command line/command prompt/terminal to send an SMS to yourself. You can expect to receive your SMS within 3 minutes. On a trial account, if you are sending an SMS to someone else, add their number to the verified caller ID first.
PC - Powershell (Older than Windows 10 version 1803)
Install Powershell if needed, and then open the Windows PowerShell.
# Twilio account info and phone numbers.
$sid = "ACCOUNT_SID"
$token = "AUTH_TOKEN"
$phone_number = "PHONE_NUMBER"
$verified_number = "VERIFIED_NUMBER",
# Twilio API endpoint and POST params
$url = "https://api.twilio.com/2010-04-01/Accounts/$sid/Messages.json"
$params = @{ To = $verified_number ; From = $phone_number ; Body = "Hello from Twilio" }
# Create a credential object for HTTP basic auth
$p = $token | ConvertTo-SecureString -asPlainText -Force
$credential = New-Object System.Management.Automation.PSCredential($sid, $p)
# Make API request, selecting JSON properties from response
Invoke-WebRequest $url -Method Post -Credential $credential -Body $params -UseBasicParsing | ConvertFrom-Json | Select sid, body
- Replace
$VERIFIED_NUMBER
with the verified phone number you used to sign up with, formatted with a '+' and country code, e.g. +16175551212 (E.164 format). - Replace
$PHONE_NUMBER
with the phone number you just purchased, formatted with a '+' and country code, e.g. +14087419548 (E.164 format). - Replace
$ACCOUNT_SID
and$AUTH_TOKEN
with the credentials here on the account dashboard.
PC - cURL (Windows 10 version 1803 or newer)
Open the Command Prompt.
curl -X POST https://api.twilio.com/2010-04-01/Accounts/%ACCOUNT_SID%/Messages.json ^
--data-urlencode "Body=Hi there from Twilio" ^
--data-urlencode "From=%PHONE_NUMBER%" ^
--data-urlencode "To=%VERIFIED_NUMBER%" ^
-u %ACCOUNT_SID%:%AUTH_TOKEN%
- Replace
$VERIFIED_NUMBER
with the verified phone number you used to sign up with, formatted with a '+' and country code, e.g. +16175551212 (E.164 format). - Replace
$PHONE_NUMBER
with the phone number you just purchased, formatted with a '+' and country code, e.g. +14087419548 (E.164 format). - Replace
$ACCOUNT_SID
and$AUTH_TOKEN
with the credentials here on the account dashboard.
Unix or MacOS
Open the Terminal app.
curl -X POST https://api.twilio.com/2010-04-01/Accounts/$ACCOUNT_SID/Messages.json \
--data-urlencode "Body=Hi there from Twilio" \
--data-urlencode "From=$TWILIO_NUMBER" \
--data-urlencode "To=$VERIFIED_NUMBER" \
-u $ACCOUNT_SID:$AUTH_TOKEN
- Replace
$VERIFIED_NUMBER
with the verified phone number you used to sign up with, formatted with a '+' and country code, e.g. +16175551212 (E.164 format). - Replace
$PHONE_NUMBER
with the phone number you just purchased, formatted with a '+' and country code, e.g. +14087419548 (E.164 format). - Replace
$ACCOUNT_SID
and$AUTH_TOKEN
with the credentials here on the account dashboard.
Additional Resources
- You can view your message delivery status in messaging logs, and your overall usage data in Messaging Insights.
- Didn’t receive the SMS?
Read our frequently asked questions
A step-by-step tutorial on sending SMS notifications
Explore a functional SMS notification app sample here. This app allows you to broadcast sms messages to a list of verified phone numbers on your trial account.
Follow our tutorial and learn line-by-line how to send SMS messages.
How to send SMS and MMS messages
Additional documentation
- Receive and reply to SMS and MMS messages
- Check delivery status of messages using status callback
- Twilio’s debugging tools
Best practices on scaling
Congratulations, you learned how to build your first SMS notification app! Before you upgrade your account to remove the trial restrictions, we recommend you read through some of the materials below to make sure you get the most out of your Twilio experience.
Note: To buy a local phone number outside of the USA or Canada, you may be required to meet regulatory compliance.
Scaling best practices
Account and pricing
Regulations and policies
- SMS regulatory guidance
- Purchase local numbers
- Twilio Service Level Agreement for Services
- Subscribe to realtime updates for Twilio services
When you are ready to upgrade, simply go to the account dashboard and select the “Upgrade Project” button.