OH3: querying thing in REST results in UID must have at least 3 segments

  • openHABian 3.4.3 on rPi4 with 4GB

I thought I have a look at the REST API.

Using it via the UI on the openHABian machine or via SSH terminal and curl, I get the same error:

curl -X GET --header "Accept: application/json" "http://192.168.1.5:8080/rest/things/smart_plug_12" -u openhab:openhab

"{\"error\":{\"message\":\"UID must have at least 3 segments: [smart_plug_12]\",\"http-code\":500,\"exception\":{\"class\":\"java.lang.IllegalArgumentException\",\"message\":\"UID must have at least 3 segments: [smart_plug_12]\",\"localized-message\":\"UID must have at least 3 segments: [smart_plug_12]\"}}}"

Copying the UI curl command and using it in a terminal shows the same error.

The thing exists and is online:
image

The API seem to work when issuing:

curl -X GET --header "Accept: application/json" "http://192.168.1.5:8080/rest/sitemaps"

… returning the sitemaps I have.

I also tried:

curl -X GET --header "Accept: application/json" "http://192.168.1.5:8080/items/SmartPlug_012_Voltage"

… which results in no response (as in, the cursor in the terminal comes back, indicating no reply whatsoever).

What am I missing?

You are missing the word rest.

http://192.168.1.5:8080/rest/items/SmartPlug_012_Voltage

:smiley: well spotted, thanks, but not so fast…

This is correct for the …

OK, having corrected that, I get the proper result:

# [2024-07-09 10:19] maxg@x570 ~ $ 
curl -X GET --header "Accept: application/json" "http://192.168.1.5:8080/rest/items/SmartPlug_012_Voltage"
{"link":"http://192.168.1.5:8080/rest/items/SmartPlug_012_Voltage","state":"243","stateDescription":{"minimum":0.0,"maximum":270.0,"step":1,"pattern":"%s","readOnly":true,"options":[]},"editable":true,"type":"Number","name":"SmartPlug_012_Voltage","label":"SP12 Voltage","category":"","tags":[],"groupNames":["grp_Smart_Plug_012"]}

However, the main problem still exists (and that has the correct syntax). :slight_smile:

OK, I figured it out…

The reference to UID must have at least 3 segments is as simple as this:
mqtt:topic:mosquitto:smart_plug_12

In my case there are four:

  1. mqtt:
  2. topic:
  3. mosquitto:
  4. smart_plug_12

… as it says “at least 3”.

Thanks in case you pondered over this.

Can you paste the command that worked so others can use it?

Thanks

Sure :slight_smile:

What I posted (in O.P. #1):

http://192.168.1.5:8080/rest/things/smart_plug_12

What it should have been:

http://192.168.1.5:8080/rest/things/mqtt:topic:mosquitto:smart_plug_1

The full command in a terminal:

curl -X GET --header "Accept: application/json" "http://192.168.1.5:8080/rest/things/mqtt:topic:mosquitto:smart_plug_12" -u username:password

Just to provide some elaboration, the UID of a Thing has at a minimum of 4 segments. Things that work with a bridge have four. The segments are separated by :.

For a stand alone Thing the UID follows <binding_id>:<type_id>:<thing_id>. For a Thing that is under a Bridge the UID follows <binding_id>:<type_id>:<thinkg_id_from_bridge>:<thing_id>. Given mqtt:broker:mosquitto as the Thing UID for the MQTT Broker Thing (i.e. the Bridge), mqtt:topic:mosquitto:smart_plug_12 would be a UID.

All three/four+ segements make up the UID. You can’t just use the last part.

1 Like