I’m struggeling with incooperating an API Token into a
Using BasicAuth it works like this:
var return = HTTP.sendHttpGetRequest("http://user:firstname.lastname@example.org:8080/rest/things/systeminfo%3Acomputer%3AMyComputerName", 10000);
According to the HTTP Action-docs using DSL it should work like this:
val headers = newHashMap("Cache-control" -> "no-cache")
val output = sendHttpGetRequest("https://example.com/?id=1", headers, 1000)
Howto convert that (especially the
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")
var headers = newHashMap("Authorization" -> "Bearer oh.MyToken.qwertz");
Expected an operand but found > pointing to the
var headers = ;
headers["Authorization"] = "Bearer MyToken";
headers["WWW-Authenticate"] = "Basic";
Worth a try
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
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. 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
 to access the elements and have to use
Another name for a map is a
Thank you for the explanation
Indeed, associative array is another name for a map/dict.