Syntax for sendHttpGetRequest in OH3 ECMA script?

I’ve looked far and wide and not finding the answer to this one. In DSL, it is as simple as sendHttpGetRequest(url,timeout).

Doing this in an OpenHab 3 ECMA script generates an error Script execution of rule with UID 'camera_trigger_all' failed: ReferenceError: "sendHttpGetRequest" is not defined in <eval> .

I’m not surprised it needs to be coded a little different. Just can’t find it.

1 Like


Though if the returned output is gzip encoded then I dont know how to decode that
Better to use the http binding

One line in DSL is now 15 lines of code? There must be something I’m missing here?

I am using http requests in my ECMA Script rules to send commands to my radio.
For me it works to add the HttpUtil namespace in the rule an then use the executeurl function.


var HttpUtil        = Java.type("")

HttpUtil.executeUrl("GET", radioIpAdress + "/main/setVolume?volume=up&step=1", 2000)

Java function from openhab-core for reference:


Thanks for the code snippet!
Was looking for hours to do the same (pinging and did not find any good solution to translate the sendHttpGetRequest to ECMA. With your code it works!

1 Like

Fantastic! That’s way better than 15 lines of code. Thanks

But to come back to the original problem: I don’t see it as very handy to find out the correct namespace before being able to use functions like these.

And the devs also see this as a problem:

1 Like