JSON Format for REST API Item Update

Hello,

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.

Thank you! Looks like my issue is I cannot specify “text/plain” from WirelessTags and thus I am out of luck on this approach.

I have the same issue with the iPhone app Geofency.
Also here it is not possible to match the specific syntax of the OH Rest Interface.

I have seen ugly workarounds in which people use a PHP server to receive the message and then reformat the message to send it to OH.

But this is at least for me unacceptable. I do not want to run a server for cost, effort and security reasons.

Also the popular MQTT protocol is only half way support in our overall concept.
It would be great if myopenhab could act as a broker for MQTT.

What specifically are you trying to achieve with the WirelessTags? I’ve got a number of them doing things with my OH setup.

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.

OK, this isn’t how I have it working so I can’t give you a surefire answer i’m afraid.

You’ve enabled the checkbox that makes the URL call come from a private IP address?

A quick look online indicates text/plain isn’t easily definable.

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.