This script will send SMS via Huawei USB lte modem API with tool/fetch (tested with E3372)
I hope can be helpful :)
github: https://github.com/NikolayDachev/Router ... endSMS.txt
:global sendSMS do={
# Send SMS messages via Huawei LTE modem API (tested with E3372)
# global vars:
# lteIP - lte modem ip address (api)
# phone - sms destination phone number
# sms - sms text message
# usage example
# :global sendSMS
# :put [$sendSMS lteIP="192.168.8.1" phone="+35912345678" sms="test sms via lte api"]
#
:local getBetween do={
# "CuriousKiwi - mikrotik forum"
# This is a basic parser, can be used for XML
# It takes three parameters:
# inputString - The main string
# betweenStart - Text AFTER this point will be returned
# betweenEnd - Text BEFORE this point will be returned
:local posStart 0;
:if ([:len $betweenStart] > 0) do={
:set posStart [:find $inputString $betweenStart]
:if ([:len $posStart] = 0) do={
:set posStart 0
} else={
:set posStart ($posStart + [:len $betweenStart])
}
}
:local posEnd 9999;
:if ([:len $betweenEnd] > 0) do={
:set posEnd [:find $inputString $betweenEnd];
:if ([:len $posEnd] = 0) do={ :set posEnd 9999 }
}
:local result [:pick $inputString $posStart $posEnd];
:return $result;
}
# get SessionID and Token via LTE modem API
:local urlSesTokInfo "http://$lteIP/api/webserver/SesTokInfo";
:local api [/tool fetch $urlSesTokInfo output=user as-value];
:local apiData ($api->"data");
# pars SessionID and Token from API session data
:local apiSessionID [$getBetween inputString=$apiData betweenStart="<SesInfo>" betweenEnd="</SesInfo>"];
:local apiToken [$getBetween inputString=$apiData betweenStart="<TokInfo>" betweenEnd="</TokInfo>"];
# header and data config
:local apiHead "Content-Type:application/x-www-form-urlencoded,Cookie: $apiSessionID,__RequestVerificationToken:$apiToken";
:local sendData "<?xml version=\"1.0\" encoding=\"UTF-8\"?><request><Index>-1</Index><Phones><Phone>$phone</Phone></Phones><Sca></Sca><Content>$sms</Content><Length>-1</Length><Reserved>1</Reserved><Date>-1</Date></request>";
# send SMS via LTE modem API with fetch
/tool fetch http-method=post output=user \
http-header-field=$apiHead \
url="http://$lteIP/api/sms/send-sms" \
http-data=$sendData;
}