Struggling with Openhab 3 HTTP binding.
Returned to OH years later (last tried early OH2). Previously I configured openhab all via files ie .things .items but decided to try UI for OH3. I like to stick to one or the other, I lose track of things otherwise.
And unfortunately the Binding page i could find didnt really comment on UI.
Seen quite a few questions with similar ish questions but not been able to translate them to my scenario. Would anyone that understands the binding maybe be able to add a translation portion to the wiki, ie hereās curl layout and how it would be input into binding for several different curl layouts.
What Iām looking to do in the HTTP binding is the same as what this curl command does:
Essentially end goal is when a shelly door sensor item changes state use a rule to switch a āNotification itemā aka Front Door Alarm, that will send that curl command which posts a message to a group chat on nextcloud talk (a chat service).
So far this is what Iāve got. Things Iāve struggled with: 1. Getting it to work, 2. Headers specifically their layout. 3.What box is best for posting this portion of curl ā{ātokenā: āhiddentockenā, āmessageā: āFront Door openā }ā. Iāve used on/off but wasnāt sure if that would work.
If you want to add Json payload to your message and use custom headers I would go with a rule and a script action like sendHttpPostRequest(String url, String contentType, String content, Map<String, String> headers, int timeout)
Iāve used HTTP binding previously to read states and even change them but for some reason I cant decipher the wiki to translate my curl command into the binding.
Anyone got a similar curl command I could utilise to help translate. The niche parts of my request seem to be multiple headers, and the fact thereās JSON content I want to send back.
Sorry I missed this thread initially. Iāve got the http binding communicating with Nextcloud talk. Hereās the config of my thing and the channel I use most:
As you can see there are a couple big differences to what you had posted:
You donāt really need the Accept header, and your OCS-APIRequest header is still formatted with a : instead of the proper =. If you do need more than one header ever, then each header you add should be on a new line in the header box. Then code would look like this:
I think it only works if you change the basic authentication to the preemptive basic authentication
If at some point you want to get responses into OH youāll need to set this to Get instead. Minor issue if youāre only ever sending messages.
My payload for this channel looks very different because I have it set up so that I can send any string that I set the item to, but the regular expression in my commandTransformation just puts that string into the simple {"message": "[string here]"} json. You donāt need to add the token to the payload object. Again. not a huge issue, if this has worked for you in the past then clearly the API just ignores unexpected keys in the payload.
I think thatās it. If you correct those issues I suspect that youāll find it works.