Hi,
I don’t know if it’s the same…I use this headers variable with sendHttpPutRequest and it’s working with OH Api, replace “MyToken” with your actual token.
val headers = newHashMap("Authorization" -> "Bearer MyToken", "WWW-Authenticate"-> "Basic")
I don’t know if it’s working in javascript too…but maybe could give you some hint.
Just to add a little bit of explanation and correct some terminology.
newHasMap is a Rules DSL thing. It doesn’t exist in any of the other languages. It’s just a shorthand for new HashMap<Object,Object>().
The object created by newHashMap is a java.util.HashMap. That’s right, it’s a Java HashMap, not something native to Rules DSL.
A HashMap is not an array. It might be a quibble but there is an important distinction in programming between a map and an array. A map has N values that are accessed/indexed by a key. The key can be almost anything, a string, number, etc. An array has N values and can only be accessed by a numerical index. If you want the fifth element you’d use myarray[4]. Note, Rules DSL does not support the creation of arrays, but you can use a java.util.ArrrayList instead. That’s why when you have a List (e.g. MyGroup.members) you can’t use [4] to access the elements and have to use .get(4).
Another name for a map is a dict. And that is what you’ve shown how to create in JavaScript, a native JavaScript dict. See JavaScript Arrays for how to create JavaScript Arrays. But you could create a java.util.HashMap too if you wanted even in the JavaScript.
I was imprecise indeed…I’m not familiar with java/javascript terminology, I come from PHP where you just call them array…or “associative array” when you want to be accurate
Many thanks @florian-h05 for the swift reply. Your answer triggered me. So I changed the URL the one where my OH can be accessed via my reverse proxy with a sigend letsencrpyt certificate and it works now.
Basically I was just playing around with JS scripts, tried to apply JSON.stringify to an items.getItems object. As that did not work I tried to get the items from REST API.
That’s because the Item object doesn’t have the properties like state, name, label etc as actual properties, but instead they are getters which retrieve and return the state, name, label etc „on the fly“