How to provide multiple headers for HTTP binding in the things file?

Hello,

I am looking for the example how to specify multiple headers in the definition of the http binding. I know that I can enter them using UI interface, but as I keep all my configuration in the text files, I would like to do that inside things file.

According to the documentation HTTP - Bindings | openHAB headers’ Format is “header=value”., but there is no example for to provide several headers. Single header works, but none of the combinations using , or newline.

Please help me with correcting this definition

Thing http:url:foo "Foo" [ 
    baseURL="https://example.com/api/v1/metadata-api/web/metadata", 
    headers="key1=value1,key2=value2,key3=value3",
    refresh=15] {
    Channels:
        Type string : text "Text" [ stateTransformation="JSONPATH:$.metadata.data" ]
}

I am using OpenHab 3.0.1 on RPi4.

Thanks in advance,
Michał

I also use files for the HTTP binding. One thing you can try is setup your Things and Channels using the UI, then switch to the Code tab to view the YAML that has been created. You can then use this to derive the Things file configuration. Feel free to post the YAML here and we can try…

I know about Code tab, but it is providing thing definition in yaml format, which is not compatible with syntax for things files. It the yaml format there is not problem with defining multiple headers.

Ok, here is the yaml version. How to convert it to things file?

UID: http:url:foo
label: Foo
thingTypeUID: http:url
configuration:
  authMode: BASIC
  headers:
    - key1=value1
    - key2=value2
    - key3=value3
  ignoreSSLErrors: false
  baseURL: https://example.com/api/v1/metadata-api/web/metadata
  refresh: 30000
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048

Thing http:url:foo "Foo" [ 
	baseURL="https://example.com/api/v1/metadata-api/web/metadata", 
	headers="key1=value1", "key2=value2", "key3=value3",
	refresh=15] {
		Channels:
			Type string : text "Text" [ stateTransformation="JSONPATH:$.metadata.data" ]
}

which ends up with this as its read-only YAML:

UID: http:url:foo
label: Foo
thingTypeUID: http:url
configuration:
  authMode: BASIC
  headers:
    - key1=value1
    - key2=value2
    - key3=value3
  ignoreSSLErrors: false
  baseURL: https://example.com/api/v1/metadata-api/web/metadata
  refresh: 15
  commandMethod: GET
  timeout: 3000
  bufferSize: 2048
channels:
  - id: text
    channelTypeUID: http:string
    label: Text
    description: null
    configuration:
      mode: READWRITE
      stateTransformation: JSONPATH:$.metadata.data

which seems to match your UI generated YAML.

This solved the problem. I would say it is not obvious syntax. I have updated HTTP binding documentation.
Thank you @hafniumzinc for the quick help.