SMS Sending via API?

As POST/GET and I/O POST/GET is removed in RutOS 7.14 I need to change to the API.
I am struggling with sending a SMS via the API. It was so easy using POST/GET.

Could you please provide an example as the documentation does not have an example in.

I use:
curl -X POST “https://192.168.1.254/api/messages/actions/send
-H “Content-Type: application/json”
-H “Authorization: Bearer 178e28e97019c8d461a3c50d30dec26e”
-d ‘{“number”: “+phonenumber”, “message”: “test”, “modem”: “1-1”}’
-k

and I get back:
{“success”:false,“errors”:[{“source”:“Validation”,“code”:102,“error”:“No arguments provided for action”,“section”:“send”}]}

I am not sure about what to use for modem as the documentation says

  • modem(required) string
    Identifier of the modem from which messages will be send
    Enum:[ 1-1 = Primary,]

It also looks like it needs to be an admin login to send a SMS.

Is this true?

Thanks !

Greetings,

Could you confirm whether you’re performing the initial authentication action before executing the API call to send the SMS? In the new RutOS API, you first need to authenticate to receive a valid session token before calling any endpoints.

You can find the instructions on authentication here:

RutOS API Authentication Documentation

Here’s the API SMS sending call example:

{
  "method": "POST",
  "url": "/api/messages/actions/send",
  "headers": {
    "Content-Type": "application/json",
    "Authorization": "Bearer <AUTH_TOKEN>"
  },
  "body": {
    "data": {
    "number": "+37XXXXXXXXX",
    "message": "test",
    "modem": "2-1"
  }
  }
}

Regarding your modem parameter — the identifier might differ depending on your specific device modem. To check the actual modem ID, you can run this command via SSH:

cat /etc/board.json | jsonfilter -e '@.modems[0].id'

Alternatively, the modem ID can be found in the /etc/config/network config file under the config interface 'mob1s1a1' section by looking for the option modem line.

I hope this clarifies it, and feel free to ask if you have any questions or need assistance here.

Best regards,

Hi,

Data structure is wrong. It should look something like this: {"data": {"number": "+phonenumber", "message": "test", "modem": "1-1"}}

Thanks,

yes I do the authentication with: (remark User and passwords are changed here)
curl -X POST “https://192.168.1.254/api/login
-H “Content-Type: application/json”
-d ‘{“username”: “user”, “password”: “password”}’
-k
and I get back:
{“success”:true,“data”:{“username”:“user”,“token”:“eb300d60dff3b6ef388dc1bd5ca24595”,“expires”:299}}

Than I ask for the modem:
curl -X GET “https://192.168.1.254/api/modems/apns/status
-H “Content-Type: application/json”
-H “Authorization: Bearer eb300d60dff3b6ef388dc1bd5ca24595”
-k
I get back:
{“success”:true,“data”:[{“apns”:[{“password”:“”,“apn”:“web.yesss.at”,“user”:“”,“id”:324,“carrier”:“yesss!”,“pdptype”:“0”,“auth”:“none”}],“modem”:“1-1”}]

But send Message does not work:
(I am not allowed to put in the curl command a third time.
3 links limitation for new users, forum editor thinks command example is a link)
Command is like in my first post with
-H “Content-Type: application/json”
-H “Authorization: Bearer eb300d60dff3b6ef388dc1bd5ca24595”
-d ‘{“number”:“+phonenumber”,“message”:“This is an SMS”,“modem”:“1-1”}’
-k

I get back:
{“success”:false,“errors”:[{“source”:“Validation”,“code”:102,“error”:“No arguments provided for action”,“section”:“send”}]}

Do you have any idea?

It is the correct structure using curl command -d.
I did not see any mistake.
If I am wrong please point out the mistake.
Thanks.

You are missing “data” object in root object. Compare my object with yours.

1 Like

Thanks so lot Dainius you are right!

With the line:
-d ‘{“data”:{“number”:“+phonenumber”, “message”:“This is an SMS”, “modem”:“1-1”}}’
it worked.
I got:
{“success”:true,“data”:{“sms_used”:1}}

This topic was automatically closed 2 days after the last reply. New replies are no longer allowed.