Community discussions

MikroTik App
 
skocdopolet
just joined
Topic Author
Posts: 2
Joined: Fri Nov 10, 2017 11:40 pm

REST API - Send SMS

Sun Feb 27, 2022 3:57 pm

Hello,

I have a mikrotik router with LTE interface. I want to send SMS via REST API, but I'm not able to be success.

This command runs OK:
curl -k -u admin: 'https://192.168.8.95/rest/tool/sms'

With this result:
{"allowed-number":"","auto-erase":"false","channel":"0","last-ussd":"","port":"lte1","receive-enabled":"true","secret":"","sim-pin":"","status":"running"}

I am trying to send SMS with this command:
curl -k -u admin: 'https://192.168.8.95/rest/tool/sms/send?phone-number:+420123123123&message=OK'

I got this error
{"error":500,"message":"Internal Server Error"}



Could anyone help me please?

Thank you
Tomas
 
elico
Member Candidate
Member Candidate
Posts: 143
Joined: Mon Nov 07, 2016 3:23 am

Re: REST API - Send SMS

Sun Mar 27, 2022 7:18 am

Hello,

I have a mikrotik router with LTE interface. I want to send SMS via REST API, but I'm not able to be success.

This command runs OK:
curl -k -u admin: 'https://192.168.8.95/rest/tool/sms'

With this result:
{"allowed-number":"","auto-erase":"false","channel":"0","last-ussd":"","port":"lte1","receive-enabled":"true","secret":"","sim-pin":"","status":"running"}
I am trying to send SMS with this command:
curl -k -u admin: 'https://192.168.8.95/rest/tool/sms/send?phone-number:+420123123123&message=OK'

I got this error
{"error":500,"message":"Internal Server Error"}



Could anyone help me please?

Thank you
Tomas


The next script should help you:
https://gist.github.com/elico/2755efac1 ... 186e176ed8
#!/usr/bin/env bash

ALLOWED_NUMBERS_FILE="destinations.txt"
MOBILE_NUMBER="$1"

DRY_RUN="0"

if [ -f "dry-run" ];then
        DRY_RUN="1"
        echo "### RUNNING IN DRY RUN MODE ###"
        echo
        echo
fi

if [ -z "${MOBILE_NUMBER}" ];then
        echo "Missing mobile number"
        exit 1
fi

grep "${MOBILE_NUMBER}" "${ALLOWED_NUMBERS_FILE}" >/dev/null
if [ "$?" -gt "0" ];then
        echo "This mobile number: \"${MOBILE_NUMBER}\" is not allowed"
        exit 3
fi

MSG="$2"

if [ -z "${MSG}" ];then
        echo "Missing message text to send in the sms"
        exit 2
fi

USER="admin"
PASSWORD="1234"

LTE_ROUTER_ADDRESS="192.168.88.1"
URL="https://${LTE_ROUTER_ADDRESS}/rest/tool/sms/send"

echo "Sending sms to: \"${MOBILE_NUMBER}\" via URL: \"${URL}\""
echo "Message: \"${MSG}\""
JSON_DATA="{\"port\" : \"lte1\", \"message\" : \"${MSG}\", \"phone-number\" : \"${MOBILE_NUMBER}\"}"

if [ "${DRY_RUN}" -eq "0" ];then
        curl -k -u ${USER}:${PASSWORD} ${URL} \
                -H "Content-Type: application/json" \
                --data "${JSON_DATA}"
else
        echo
        echo "DRY RUN, should send the next JSON to the LTE Router"
        echo
        echo "${JSON_DATA}"
fi

Who is online

Users browsing this forum: GoogleOther [Bot] and 11 guests