How to call an API from node-red Teltonika RTU241

Hi I have a Teltonika RTU241 4G modem / SMS gateway.
I'm trying to send SMS messages from my application, I would like to use the Teltonika API to do that.
I can send it successfully from the command line however this uses CURL and I would rather go straight to the API. I tried various methods but just didn't get there. Any help would be greatly appreciated.

Regards

The API lists the following

Requests Value

{
    "data": {
        "number": "string",
        "message": "string",
        "modem": "string"
    }
}

Response Value

{
    "success": "boolean",
    "data": {
        "sms_used": "integer"
    }
}

Schema

  • data(required)

object

  • number(required)

string($phonedigit)

To whom the message will be sent. The number must be specified in full format, country code included. e.g., +37000000000

  • message(required)

string($string)

Message to send

  • modem(required)

string

Identifier of the modem from which messages will be send

Enum:[
* 3-1 = Primary,
* 1-1 = Primary,
* 2-1 = Primary,
* 1-1.4 = Primary,
* 1-1.2 = Secondary,]

This is the link to the API page

Did you try using the http request node?

Is node-red running in the same place as where you run the curl command?

Is node-red running in a container/docker/HA PLUGIN?

Answer: No, I run the CURL straight from the terminal in Linux

Is node-red running in the same place as where you run the curl command?

Answer: yes (but this is not relevant as I would like to use the API)
The CURL HTTP is working fine ( from the command line), but it would be difficult, I think, to programmatically change the phone number I send in the curl?
Do you have an example of a CURL call from Node-Red?

Is node-red running in a container/docker/HA PLUGIN?

Answer: No

To describe the problem.

I have multiple devices that communicate via MQTT and I ingest these into node-red.
I know how to programmatically send SMS messages to different phones depending on what alarm is raised by the devices. I have connected with NTFY (local install) and that works very nicely. However I would like also to send notifications via SMS not using a paid service and rather using my SMS gateway, hence I'm using the RUT241 from Teltonika. This device has an API that allows me to send SMS through an API call as described in the below link.

https://developers.teltonika-networks.com/reference/7.6.3/v1.1/messages/#post-messages-actions-send

However, my problem is that I don't understand how to invoke this API call from node-red.

Regards

Hi
Steve mentioned the http request node as curl sends http request, so you can use the http request node.
Read through this tutorial Teltonika Networks Web API

You first send a request to get the api key to later use in the send message request. so it looks like you need two requests.

Here is a basic set up of a http request node that should work for you (untested)

[{"id":"33fa79611fa1d480","type":"http request","z":"e1ef5728e9206b4a","name":"","method":"use","ret":"obj","paytoqs":"ignore","url":"","tls":"","persist":false,"proxy":"","insecureHTTPParser":false,"authType":"","senderr":false,"headers":[],"x":370,"y":460,"wires":[["72b71335.355a9c"]]},{"id":"72b71335.355a9c","type":"debug","z":"e1ef5728e9206b4a","name":"","active":true,"tosidebar":true,"console":false,"tostatus":false,"complete":"true","targetType":"full","statusVal":"","statusType":"auto","x":610,"y":440,"wires":[]},{"id":"f227d8165e034e56","type":"inject","z":"e1ef5728e9206b4a","name":"","props":[{"p":"url","v":"http://<DEVICE_IP>/api/login","vt":"str"},{"p":"method","v":"POST","vt":"str"},{"p":"payload"}],"repeat":"","crontab":"","once":false,"onceDelay":0.1,"topic":"","payload":"{\"username\":\"<USERNAME>\",\"password\":\"<PASSWORD>\"}","payloadType":"json","x":130,"y":460,"wires":[["33fa79611fa1d480"]]}]

You will need to add the correct urls in msg.url
the body of the request is the curl info after the -d, which goes in msg.payload. The -h is the headers which would go in msg.headers, but the request node will auto append that header if the payload is an object.

Have ago and report any error you get in the debug node connected.

Yes I get that.
cURL makes http requests.
The http request node makes http requests.

So I am essentially saying "use a http request node"

1 Like

Hi E1cid, I have been banging my head against the wall, I'm sure there is a simple answer but I just can not get this right. :frowning: my HTTP skills are zerro.

I can send this string directly from the browser and it works. How can this be done in node-red?

http://10.10.10.254/cgi-bin/sms_send?username=admin&password=mypassword&number=617989327733&text=test_message

I can't believe I can't work this out.

Any one can get me out of my misery, please.

Cheers

Not really possible without context!

Did you set the method to get on the HTTP request node?

Are you triggering it (via an inject node for example)?

Were there any responses or errors?

What are you putting in the URL field?

Might this help at all?
YMMV

If you look at the tutorial, first you need to send to login url, that will return a api key. So lets get that running first. once you have that you can move on to the send message url.

Thank you all for your help! The saying "Start with the basics" this something to be adhered to!
Right at the beginning of this thread, someone asked "Do you run this locally?" and I answered "Yes". This was not true.
Everything is working fine now. The first flow worked perfectly.
I'm very sorry for all the confusion, please accept my apologies. I will try to do better next time, I promise.

1 Like