I have a post request which is working fine in postman and even in a rule with sendHttpPostRequest
val url = "https://api.solarmanpv.com/device/v1.0/currentData?language=en"
val token = "oxoxoxoxox"
val content = '{"deviceSn": "serialnr"}'
val headers = newHashMap("Authorization" -> "Bearer " + token)
var String request = sendHttpPostRequest(url, "application/json", content, headers, 3000)
Now I’m trying to convert this to the http bindng, but I don’t understand where I need to put the content part. (this is the same as body or payload, correct?)
Do I need to put this in the stateContent param in the channel?
If I don’t fill in this param I get
This is usually used to set up a periodic retrieval of data from some remote service, i.e. to update an OH Item’s state.
It’s not like your on-demand sendHttpPostRequest,
is related to you sending a command to an OH ltem, which triggers the HTTP sending.
No.
What exactly is your purpose, sending a POST when you command an Item? (Having to guess because you didn’t tell us when your rule version runs.)
Then you do not want any stateMethod or refresh, but do need to fix commandMethod
It’s the unique identity of the little job the binding runs to carry out the requested tasks. In this case I think that’s the “every 30 seconds POST” that you set up.
This post request is actualy grabbing data from my solarpanel cloud. So I wanted to trigger this every 5 minutes (now setup every 30s indeed). This post request returns a json offcourse which I wanted to transform into some items.
I already changed commandMethod to POST, but same message.
And to be clear, everything works in a rule, but I thought the HTTP binding is more suiteable for this.
If I understood right, you want to send a HTTP request with a body part. I did something similar, in my case I sent a PUT request containing a JSON payload.
There is no openHAB transformation that allows to send a HTTP body, you need to create a map. To do so place a file in your transformations folder (usually /etc/openhab/transformations) with the name of your choice and the .map extension. As an example let’s use light.map. Then put some content where you map the command to an output. i.e.:
ON: { LIGHT=1 }
OFF: { LIGHT=0 }
In the command transformation put the value MAP:light.map
Once your channel gets the command ON, the HTTP call with body { LIGHT=1 } will be sent to your device. If the command is OFF, the body will contain { LIGHT=0 }