read

Send notification SMS from command line

There is a very easy way to send SMS notifications from a unix command line. Using this guide and example bash script provided below, you can be up and running in less than 10 minutes.

1) Sign up for an account and get to the Dashboard

Sign up for an account. 

Make sure you also verify your phone number, as this is required to send SMS messages. If you skipped the number verification during sign-up, then you can add it later by selecting “+ Add Sender” from the Dashboard Sender selection drop-down menu.

2) Get your API username and password

First you need to know the IP address of your server that you'll be using to send SMS messages via an API call. Find out your IP address from the command line:

$ echo `curl -s http://automation.whatismyip.com/n09230945.asp`

Now go and get your API username and password from the dashboard.

3) Get the bash script

Save following script to a file, for example sendSMS.sh

#!/bin/bash
#set -x

# Configure this!
MESSENTE_API_USERNAME=00000000000000000000000000000000
MESSENTE_API_PASSWORD=11111111111111111111111111111111

# ---------------------------------------
# Do not modify anything below this line
# ---------------------------------------

if [ ! "$#" -eq 2 ]; then
 echo "ERROR 2 arguments required, $# provided"
 echo "-------------------------------------------------"
 echo "Usage: bash $0 full_phone_number text_message"
 echo "Example: bash $0 4463773683 "This is a test message""
 echo "-------------------------------------------------"
 exit 1
fi
echo -n "Sending SMS..."
curl -o /tmp/send_sms_result 
 -s http://api2.messente.com/send_sms/ 
 -d username=${MESSENTE_API_USERNAME} 
 -d password=${MESSENTE_API_PASSWORD} 
 --data-urlencode "to=$1" 
 --data-urlencode "text=$2"
API_RESULT=$( cat /tmp/send_sms_result | sed 's/( )(.*)/1/' )
API_RESULT_FULL=$( cat /tmp/send_sms_result )
if [ $API_RESULT == "OK" ]; then
 echo " done" 
 exit 0
else
 echo " failed (${API_RESULT_FULL})"
 exit 1
fi

4) Try out your new SMS sending function

You could make this file executable, or just call it directly:

$ bash sendSMS.sh 4463773683 "This is a sample text message"

And you are done! Now you can easily use this script to send out SMS messages

Troubleshooting

First, make sure you edited the script to include your personal API username and password.

Secondly, check the error code from Messente API documentation.

Still having troubles? Contact us development@messente.com and we will help you with it.

Omni-channel messaging is here

Check out our latest webinar going over the details (plus a demo) of the intelligent A2P messaging API.
Learn more