Rules with sendHttpPutRequest and AuthToken

Dear Community,

In my approach of creating a rule in OpenHAB 3.2.0 where I need to send a HTTP Put Request to the OpenHAB REST API, I failed to configure sendHttpPutRequest correctly so that the Authentication Token required to access to the OpenHAB REST API is properly handed over.

I tried the following Rules DSL code:

sendHttpPutRequest("http://<MyAuthToken>:@localhost:8080/rest/things/knx%3Aip%3Arouter/enable", "application/json", "false")

However, the result is:

2022-03-18 00:28:25.037 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID 'knx-1' failed: Index 1 out of bounds for length 1 in knx
javax.script.ScriptException: Index 1 out of bounds for length 1 in knx
	at org.openhab.core.model.script.runtime.internal.engine.DSLScriptEngine.eval(DSLScriptEngine.java:135) ~[?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.lambda$0(ScriptActionHandler.java:62) ~[?:?]
	at java.util.Optional.ifPresent(Optional.java:183) [?:?]
	at org.openhab.core.automation.module.script.internal.handler.ScriptActionHandler.execute(ScriptActionHandler.java:59) [bundleFile:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.executeActions(RuleEngineImpl.java:1180) [bundleFile:?]
	at org.openhab.core.automation.internal.RuleEngineImpl.runRule(RuleEngineImpl.java:988) [bundleFile:?]
	at org.openhab.core.automation.internal.TriggerHandlerCallbackImpl$TriggerData.run(TriggerHandlerCallbackImpl.java:89) [bundleFile:?]
	at java.util.concurrent.Executors$RunnableAdapter.call(Executors.java:515) [?:?]
	at java.util.concurrent.FutureTask.run(FutureTask.java:264) [?:?]
	at java.util.concurrent.ScheduledThreadPoolExecutor$ScheduledFutureTask.run(ScheduledThreadPoolExecutor.java:304) [?:?]
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1128) [?:?]
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:628) [?:?]
	at java.lang.Thread.run(Thread.java:829) [?:?]

Worth to note, the API Explorer in OpenHAB correctly processes my request. So I know the API call as such works, but I fail to correctly code it.

I started from the example given here:

When searching the forum for various different solutions I found the Auth Token placed into a separate header field. I also found solutions not based on Rules DSL, but rather on JavaScript. However, I have Ivan’s Helper Libraries installed with the Python setup, so I was not sure whether JavaScript will work at all in my environment.

In other words, I got lost with all these various options. Does anybody have a hint for me as how to further proceed?

Thanks a lot,
Peter

Another try in Rules DSL failed:

val headers = newHashMap("Authorization" -> "Bearer <MyAuthToken>", "WWW-Authenticate" -> "Basic")
sendHttpPutRequest("http://localhost:8080/rest/things/knx%3Aip%3Arouter/enable", "application/json", 'false', headers, 10000)

In this case, I receive:

2022-03-18 15:28:37.016 [WARN ] [s.impl.WebApplicationExceptionMapper] - javax.ws.rs.ClientErrorException: HTTP 415 Unsupported Media Type

This approach was based on:

According to the REST API description
it needs to be "text/plain"
instead of

Yep. application/json worked up until 3.1, but stopped working in 3.2. It perhaps always should have been text/plain in the first place.