Execute a simple HTTP Action from JS script

ubuntu server

openHAB 5.2.3

After reading several posts I’l like to ask for help.

I have a display where I want to push the state of an openHab item.

if I run the code below in a web browser, the display acts as desierd.

http://192.168.1.222/rpc/Number.Set?id=200&value=22

I was trying using a HTTP Action do achive the same thing.

sendHttpPostRequest(String url, String contentType, String content)

when using the code line below the request data is not ariveing at the display and so there is an error in the log of the display.

actions.HTTP.sendHttpPostRequest("http://192.168.1.222/rpc/Number.Set?id=200&value=11.1", "text", "?id=200&value=11.9");

My questions:

  • can it be done this way?
  • there is also a HTTP Binding, would that be an option?

thanks Ernst

Hi!

I use both forms.

See below for a snippet of JS code that I use for some tests:

devicesJSON = (actions.HTTP.sendHttpGetRequest('https://demo.traccar.org/api/devices', {'Authorization': 'Basic <KEY>', 'Content-Type': 'application/json'}, 9500));
if (devicesJSON == null) {
  console.info('Traccar - return NULL');
  rules.runRule('ReportEvents', {'msgEVT': 'Traccar - return NULL', 'evtType': 'EVT_Rules'});
  return false
}
console.info(devicesJSON);
devicesOBJ = JSON.parse(devicesJSON);

AFAIK if it works in browser it is a HTTP GET request.. Not POST.

Try ‘sendHttpGetRequest’

greets

Thanks to both of you,

on the fast track the solution is simple.

however aving more time I’ will test the version from Ricardo.