[OH3 / Javascript] Trying to create a http PUT request, but failing?

I’m converting my DSL rules to javascript.

In DSL this is working.

val returnvalue = sendHttpPutRequest("http://***:***@127.0.0.1:8080/rest/things/systeminfo%3Acomputer%3Aopuspi4","application/json",systemstatus_thing, 10000)

Why isn’t the following not working in javascript?
HttpUtil.executeUrl("PUT", "http://****:*****@127.0.0.1:8080/rest/things/systeminfo%3Acomputer%3Aopuspi4", "application/json", systemstatus_thing, 10000)

systemstatus_thing is a string var holding the JSON.

I get the following error:

Script execution of rule with UID 'openHAB_processID' failed: TypeError: Can not invoke method [jdk.dynalink.beans.OverloadedDynamicMethod
 String org.openhab.core.io.net.http.HttpUtil.executeUrl(String,String,InputStream,String,int)
 String org.openhab.core.io.net.http.HttpUtil.executeUrl(String,String,int)
 String org.openhab.core.io.net.http.HttpUtil.executeUrl(String,String,Properties,InputStream,String,int,String,Integer,String,String,String)
 String org.openhab.core.io.net.http.HttpUtil.executeUrl(String,String,Properties,InputStream,String,int)
] with the passed arguments; they do not match any of its method signatures. in <eval> at line number 12

Did you solve your issue? Experiencing the same error.

Regards.

Actually my working rule looks like this:


var Exec = Java.type("org.openhab.core.model.script.actions.Exec");
var HTTP=Java.type("org.openhab.core.model.script.actions.HTTP");
var openHAB_PID =Exec.executeCommandLine(parseDuration("1s"), "pgrep", "-f", "openhab.*java");
logger.info("openHAB_PID = {}", openHAB_PID);
var headers = [];
headers["Authorization"] = "Bearer MyAPIToken";
headers["WWW-Authenticate"] =  "Basic";

systemstatus_thing=HTTP.sendHttpGetRequest("http://127.0.0.1:8080/rest/things/systeminfo%3Acomputer%3Aopuspi4",headers, 10000);
//logger.info( "systemstatus_thing_original: {}", systemstatus_thing);
systemstatus_thing=systemstatus_thing.replaceAll('"pid":([0-9]+)','"pid":' + openHAB_PID);
logger.info("before Post request");
var returnvalue = HTTP.sendHttpPutRequest("http://127.0.0.1:8080/rest/things/systeminfo%3Acomputer%3Aopuspi4", "application/json", systemstatus_thing,headers, 10*1000);
//logger.info("returnvalue: {}", returnvalue);

you need to replace MyAPIToken with your API Token and opuspi4 with your system-name.

1 Like