I’ve recently acquired a Wireless Tag monitor. It has the ability to post to an API when items change. I am struggling to get the format correct when I try to post a state update. See the HTTP thread below (via Wireshark capture):
PUT /rest/items/WT_Moisture_Zone_1/state HTTP/1.1
Host: <redacted>
Content-Length: 12
Content-Type: application/json; charset=utf-8
Connection: close
{data: "16"}
HTTP/1.1 415 Unsupported Media Type
Date: Sat, 06 May 2017 21:57:49 GMT
Content-Type: application/json
Content-Length: 282
Connection: close
Server: Jetty(9.2.19.v20160908)
{
"error": {
"message": "HTTP 415 Unsupported Media Type",
"http-code": 415,
"exception": {
"class": "javax.ws.rs.NotSupportedException",
"message": "HTTP 415 Unsupported Media Type",
"localized-message": "HTTP 415 Unsupported Media Type"
}
}
}
Any thoughts on how to format the content payload so OH2 accepts it?
According to the REST API docs (install them through PaperUI, under the Misc column). you use a POST with a content type of “text/plain” to send a command to an Item.
The body of the command is an unadorned String that can be parsed into the destined Item’s state (e.g. ON for a Switch).
You might need to use all caps (i.e. CLOSED instead of closed).
Use PUT to postUpdate to the Item instead of sendCommand. Same rules apply for the body and content type.
Really all I want to do is have the WirelessTag URL calling feature call the OH2 REST API when a value changes and update that item’s value in OH2. That seems like the most elegant approach compared to a “polling” model of OH2 having to check the WirelessTag API frequently for updates.
Yeah, checkbox didn’t help. I see the same - OH2 REST won’t take the JSON format, only text/plain, and WirelessTags doesn’t allow you to configure the format.
I opted for the “cheating” approach of using the CMD API on the classicUI. Not my preference, but no other options exist that aren’t highly convoluted.