Skip to content

Instantly share code, notes, and snippets.

@rob-watts
Created July 11, 2018 16:24
Show Gist options
  • Save rob-watts/02ac94a9b9ce42f0cf59c3e25160c332 to your computer and use it in GitHub Desktop.
Save rob-watts/02ac94a9b9ce42f0cf59c3e25160c332 to your computer and use it in GitHub Desktop.
A shell script to send an sms message via callfire api
#!/usr/bin/env bash
function usage {
programName=$0
echo "description: use this program to send an email using the SendGrid API"
echo "usage: $programName [-p \"to phone\"] [-m \"message\"]"
echo " -p The recipient phone"
echo " -m The message"
exit 1
}
while getopts ":p:m:h" opt; do
case ${opt} in
p) phone="$OPTARG"
;;
m) message="$OPTARG"
;;
h) usage
;;
\?) echo "Invalid option -$OPTARG" >&2
;;
esac
done
if [[ ! "${phone}" || ! "${message}" ]]; then
echo "A phone number AND a message is required."
usage
fi
read -rd '' payLoad << EOF
[
{
"phoneNumber": "${phone}",
"message": "${message}"
}
]
EOF
url="https://api.callfire.com/v2/texts"
statusCode=$(curl \
--write-out %{http_code} \
-X POST ${url}\
-H 'Content-type: application/json' \
-H 'Authorization: Basic YOURTOKENHERE' \
--data "${payLoad}" )
echo ${statusCode}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment