Sending API post request from Javascript

Because the tado binding only works in snapshot, I set up a secondary openHAB instance, just for tado. I now want to have certain items send values to my “real” openHAB instance, and vice versa. I thought the API would be the most easy way, and indeed, this works:

curl -v -X POST --header "Content-Type: text/plain" --header "Accept: application/json" -d "15" "http://192.168.1.9:8080/rest/items/Verwarming_studieruimte_targetTemp"

However, I want to make a JavaScript rule, which triggers this POST request. I tried the following, without success:

actions.Exec.executeCommandLine(time.Duration.ofSeconds(5), "curl -v -X POST --header \'Content-Type: text/plain\' --header \'Accept: application/json\' -d \'15\' \'http://192.168.1.9:8080/rest/items/Verwarming_studieruimte_targetTemp\'")

Result:

12:39:34.948 [WARN ] [org.openhab.core.io.net.exec.ExecUtil] - Failed to execute commandLine '[curl -v -X POST --header 'Content-Type: text/plain' --header 'Accept: application/json' -d '15' 'http://192.168.1.9:8080/rest/items/Verwarming_studieruimte_targetTemp']'

I then read about actions.HTTP.sendHttpPostRequest(), but I don’t understand its syntax. This doesn’t work:

actions.HTTP.sendHttpPostRequest("http://192.168.1.9:8080/rest/items/Verwarming_studieruimte_targetTemp", headers, "Content-Type: text/plain", headers, "Accept: application/json", data, "15")

Thanks in advance for anyone’s help!

(I also tried the Remote openHAB Binding, but if I want to update an item which is linked with the working tado binding, it always reverts to the value tado has, so I can’t change it.)

I did some more digging, and this works:

var url = "http://192.168.1.9:8080/rest/items/Verwarming_studieruimte_targetTemp"
var contenttype = "text/plain"
var content = "10"

actions.HTTP.sendHttpPostRequest(url, contenttype, content)

I don’t know what the purpose of --header "Accept: application/json" was (I had copied it from somewhere in the “community” here), but omitting it appeared to do no harm.

For future reference: for PUT requests (in order to postUpdate rather than sendCommand), the /state needs to be added to the URL:

var posturl = "http://192.168.1.9:8080/rest/items/Verwarming_studieruimte_targetTemp"
var puturl = "http://192.168.1.9:8080/rest/items/Verwarming_studieruimte_targetTemp/state"
var contenttype = "text/plain"
var content = "5"

actions.HTTP.sendHttpPostRequest(posturl, contenttype, content)
actions.HTTP.sendHttpPutRequest(puturl, contenttype, content)