Problem with HTTP Binding and POST

Hi,
I’m integrating OA with Zoneminder using Zoneminder’s REST API.
I need to check detection status, and switch motion detection ON and OFF reflecting the status of antitheft.
To turn ON and OFF motion detection i need to all the API in POST passing one parameter. I configured like this:

>[*:POST:http://192.168.1.76/zm/api/monitors/1.json?Monitor[Function]=Monitor]

But it does not work, the api return error. If I use curl to call the same API it work.

Thanks and any help would be appreciated.

Marco

What is your complete curl command for comparison?

curl -XPOST http://192.168.1.76/zm/api/monitors/1.json -d "Monitor[Function]=Monitor"

Unfortunately, the HTTP binding does not pass data in the body of the message when using the POST method. Your curl command is doing so with the -d parameter, but in your item binding string, the data is being passed as part of the URL, which the receiving end is not accepting. I think your alternative may be to use the exec binding instead of the HTTP binding and call curl to perform the HTTP POST for you.

Hi watou and thanks for explanation.
I have another question. Is possible to mix on a single Item 2 bindings?
I would like to use HTTP to retrieve values and EXEC to send command.
Thanks and regards

Yes, this works. I know of a user that has a single item that reads from his Ecobee thermostat and writes the returned temperature to an MQTT broker, all within the single item line. The syntax is { thisbinding="…", thatbinding="…" }

I’m using

{http="<[http://192.168.1.76/zm/api/monitors/1.json:5000:JS(ZM_getFunction.js)], exec=">[*:curl -XPOST]" }

but does not work. Do you have an example?

Marco

Looks like you’re missing a double quote mark at the end of the http binding string?

Yes, you’re rigth.
I fixed the syntax:

{http="<[http://192.168.1.76/zm/api/monitors/1.json:5000:JS(ZM_getFunction.js)]", autoupdate="true", exec=">[*:curl -XPOST http://192.168.1.76/zm/api/monitors/1.json -d \"Monitor[Function]=Monitor\"]" }

Http part is working, but seems exec part not. It seems command in not fired. Is there any traces in the logs of this Exec? And what i should looking for?

Regards

Hi,
I fixed.
OA do not like the double quote around the POST parameter.

Perhaps use single quotes instead around ‘Monitor[Function]=Monitor’

Hi watou,
I use your patient a little bit yet.
this is a item string, drived by a Switch widget on sitemap.
I have 2 button called Monitor and Modect.

I fire my binding on every button press:

exec=">[*:curl --user marcolino:poilkj -XPOST http://192.168.1.76/zm/api/monitors/1.json -d Monitor[Function]=---BUTTONVALUE----]"

Is it possible to pass into exec the value of the pressed button instead --BUTTONVALUE----??

Regards

The wiki page for the exec binding says you can use %2$s in place of ---BUTTONVALUE---.

You’re right, I readit so quickly prehaps.
Now all is working like a charm. Many Thanks for your help.

Regards

Marco

Encountered the same issue and also switched to the exec binding to call curl to work around it. Would be helpful when the wiki page of the http binding is updated describing this limitation and possible workaround. Wasted hours trying to get the config right… :wink:

I just updated the wiki for the HTTP binding to add a note:

:warning: It is currently not possible to send a message body, as one might do typically with the POST HTTP method. An alternative solution, in the case where the receiving web server requires a message body, might be to execute curl ... -d <data> using the [[exec binding|exec-Binding]].

2 Likes

Watou, please… I use this POST to control a webcam.

{ http=">[OFF:POST:http://myurl/decoder_control.cgi?&user= username&pwd=password&command=31] >[ON:POST:http://myurl/decoder_control.cgi?command=33&user=username&pwd= password]" }

And… is there any way to show in LOGINFO (rules) items Binding String?

I’m not sure if you are asking a question?

I’ve never seen an example of it, and without knowing for sure it seems doubtful that those inner workings are easily accessed. (Happy to be proven wrong.)

John,
You can also do it directly in a rule, using sendHttpPostRequest. This was missing from the Actions Wiki page, so I added it in, along with a few other variants from the original source.

I’ve been using it for a while to replace my Vera/MiOS SmartEnergyGroups.com Uploader.

This is handy if you want to write POST calls at higher frequency, since you can avoid launching child processes.

The downside is that these versions don’t allow headers to be passed in. The underlying HttpUtils class does, but there’s not currently a wrapper version for it (fairly trivial to add, but v1’s sorta on lockdown)

1 Like

I am a new openHAB user. Just installed it yesterday on a BeagleBoneBlack. I was using X10 and Heyu to control my home but I just bought a SmartPlug, used it to control my CoffeeMaker and hacked it so that it would respond to “http://coffee/cgi-bin/relay.cgi?on” or off or state. I think that for IoT, Wifi is the future.
So I used the demo house and modified one item:
Switch Light_GF_Kitchen_Table "Coffee Maker" (GF_Kitchen) {http=">[ON:GET:http://cafe/cgi-bin/relay.cgi?on] >[OFF:GET:http://cafe/cgi-bin/relay.cgi?off] <[http://cafe/cgi-bin/relay.cgi?state:5000:REGEX(O.*)]"}This works fine to control the coffee maker but does not work to read the current state if I turn it on or off locally.
I tried the url in my browser:
http://cafe/cgi-bin/relay.cgi?state
and the reply comes back ON\n or OFF\n.
I don’t know what the reply should be. I don’t know if mapping the output is necessary. If not, I don’t know if I still need the “:” after the 5000 ms.
I have full control over the reply. I can make it whatever I want. But there is no documentation as to what is expected for the different types of objects. What is valid. Should it be ON or OFF or on or off or 1 or 0?