HTTP Binding and OH3 API access


I would like to ask you for help setting up thing new HTTP binding to talk to OH3 API.
What I would like to do (it was working on OH2 with old http binding) is access API to get z-wave device status.

For example API url for device is:

When i go to that url there is “Authentication required” 401 error which is correct.

Using curl from cmd:

curl -X GET -u user:password --header "Accept: application/json" ""

I am getting right response with all data.

When I try to setup file with thing:

Thing http:url:zwavehttp "Z-Wave HTTP" [
	refresh=600] {
                        Type string : ZWAVE_DEVICE1 "Z-Wave Device 1 Status" [ stateExtension="zwave:device:711ae217:node40", stateTransformation="JSONPATH:$.statusInfo.status" ]

I am getting error:

[p.internal.http.HttpResponseListener] - Requesting '' (method='GET', content='null') failed: HTTP protocol violation: Authentication challenge without WWW-Authenticate header

Maybe @J-N-K can help me :slight_smile:

Probably I am making mistake somewhere but I don’t know where even after reading the documentation

I would perhaps try removing your Things file for now and setting this up first with the UI. Once that’s working then we can migrate back to the Things file.

JNK is no longer an openHAB maintainer, nor supports configurations in Things files.

WIth GUI I have created code like below:

UID: http:url:0c27989d94
label: zwavehttp
thingTypeUID: http:url
  authMode: BASIC
  ignoreSSLErrors: false
    - Accept=application/json
  password: password
  refresh: 60
  commandMethod: GET
  timeout: 10000
  username: username
  bufferSize: 2048
  - id: test
    channelTypeUID: http:string
    label: test
    description: ""
      mode: READWRITE
      stateExtension: /zwave:device:711ae217:node40
      stateTransformation: JSONPATH:$.statusInfo.status

but it produces the same error:

[p.internal.http.HttpResponseListener] - Requesting '' (method='GET', content='null') failed: HTTP protocol violation: Authentication challenge without WWW-Authenticate header

Did you try BASIC_PREEMPTIVE as auth method?

In GUI there is no BASIC_PREEMPTIVE directly

so I have put it in the code:

UID: http:url:0c27989d94
label: zwavehttp
thingTypeUID: http:url
  ignoreSSLErrors: false

But with no luck.

2021-03-09 15:39:24.506 [WARN ] [re.config.core.internal.ConfigMapper] - Could not set field value for field 'authMode': No enum constant org.openhab.binding.http.internal.config.HttpAuthMode.BASIC_PREEMPTIVE

java.lang.IllegalArgumentException: No enum constant org.openhab.binding.http.internal.config.HttpAuthMode.BASIC_PREEMPTIVE

Which version are you using?

I have version 3.0.1 delivered by default with OH3 3.01 release.

I can confirm this also:

  version: 3.0.1
  buildString: Release Build
locale: en_GB
  configFolder: /etc/openhab
  userdataFolder: /var/lib/openhab
  logFolder: /var/log/openhab
  javaVersion: 11.0.10
  javaVendor: Azul Systems, Inc.
  javaVendorVersion: Zulu11.45+27-CA
  osName: Linux
  osVersion: 4.15.0-136-generic
  osArchitecture: i386
  availableProcessors: 2
  freeMemory: 25678600
  totalMemory: 163577856
  - astro
  - http
  - mqtt
  - network
  - telegram
  userAgent: Mozilla/5.0 (X11; Ubuntu; Linux x86_64; rv:86.0) Gecko/20100101 Firefox/86.0

It could be that this was introduced later and is only available in latest milestone.

Maybe I can try tomorrow, not sure if I find the time to do so.

You have two issues.

Token Auth is currently not supported by the binding.

I have Basic Authentication enabled:

So as far as I understand my only way is to wait for next binding release?

Correct. The REST API expects the Auth header to be sent without requesting that.

Usually the flow would be

Client: „request something“
Server: „you need to auth, here is the challenge“
Client: „here are my credentials and the request again“

Step 2 is missing, so the Client (the binding) will never send the corresponding header. This can be forced by always sending the header (which is what preemptive does).

I have upgraded my openHAB to 3.1.0.M2 - Milestone Build and tested latest HTTP binding and it waorks as suggested (with BASIC_PREEMPTIVE authMode)

I will paste my config - maybe it will be useful for someone.

Thing configuration:

Thing http:url:zwavehttp "Z-Wave Status HTTP" [
                Type string : Item_1_ZWave_status	"Item 1 Z-Wave Status"		[ stateExtension="zwave:device:711ae317:node1", stateTransformation="JSONPATH:$.statusInfo.status" ]
                Type string : Item_1_Last_Wakeup	"Item 1 Last Wakeup"		[ stateExtension="zwave:device:711ae317:node1", stateTransformation="JSONPATH:$.properties.zwave_lastwakeup" ]
                Type string : Item_2_ZWave_status	"Item 2 Z-Wave Status"		[ stateExtension="zwave:device:711ae317:node2", stateTransformation="JSONPATH:$.statusInfo.status" ]
                Type string : Item_2_Last_Wakeup	"Item 2 Last Wakeup"		[ stateExtension="zwave:device:711ae317:node2", stateTransformation="JSONPATH:$.properties.zwave_lastwakeup" ]

Items configuration:

String      item_1_zwave_status		"Z-Wave Status [%s]"                {channel="http:url:zwavehttp:Item_1_ZWave_status"}
DateTime    item_1_LastWakeup		"[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]"  {channel="http:url:zwavehttp:Item_1_Last_Wakeup"}

String      item_2_zwave_status		"Z-Wave Status [%s]"                {channel="http:url:zwavehttp:Item_2_ZWave_status"}
DateTime    item_2_LastWakeup		"[%1$tY-%1$tm-%1$td  %1$tH:%1$tM]"  {channel="http:url:zwavehttp:Item_2_Last_Wakeup"}