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" "" -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:

The API seem to work when issuing:

curl -X GET --header "Accept: application/json" ""

… returning the sitemaps I have.

I also tried:

curl -X GET --header "Accept: application/json" ""

… 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.

: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" ""
{"link":"","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:

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?


Sure :slight_smile:

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

What it should have been:

The full command in a terminal:

curl -X GET --header "Accept: application/json" "" -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