sendHttpGetRequest with Authorization token

Good evening,
I am trying to write a Rule that makes an HTTP action call through “sendHttpGetRequest”.
The call in the header has the authorization token with the Bearer.
How do I insert the header on the call? What syntax should I use? I have tried with:

val headers = "{'Authorization': 'Bearer MY_TOKEN'}"
var requestSample = URL_SAMPLE
val responseSample = sendHttpGetRequest(requestSample, headers, 1000)

But without success.
How can it be done?

Thank you

I did a trial but it wasn’t successfull either.
To my impression the sendHttpGetRequest does not work with headers also it is described in the documentation. Once the header is added to the request the logfile shows:

An error occurred during the script execution: Could not invoke method: org.eclipse.smarthome.model.script.actions.HTTP.sendHttpGetRequest(java.lang.String,int) on instance: null

I would use the executeCommandLine ( exec binding ) and do a call to e.g. curl or wget instead.


i had a similar task to do and ended up to do it inside rules with shell scripts.
You can find my solution here:


Good morning,
I tried to create a rule that executes a curl script.
The script, if executed from the command line, is successful and shows me a response in JSON format.
Within the rule, however, I get no answer.
Where am I doing wrong?

var urlSample = MY_URL
var headers = " -H 'Content-Type: application/json' -H 'Authorization: Bearer " + MY_TOKEN + "'"
var curlcommand = "curl -s -X GET '" + urlSample + "'" + headers
var responseSample = executeCommandLine(curlcommand, 2000000)

Thank you

Try to echo the curlcommand to check if the string contains the command as you expect it.
Which openhab version do you use ? Have you added curl to the whitelist in case you are on latest version ?
Check that I did:

                var responseSample = executeCommandLine( "curl -s", 2000)
                logInfo( "test123", "my IP is : {}", responseSample )

Whitelist is not currently needed for executeCommandLine()

Hi Wolfgang_S,
I put logInfo on the curl call and on the curl answer.
The call is correct (if I copy/paste this string on the bash it works). The answer from Rule is empty.
I also tried to put @@ instead of spaces, but nothing.

May we see what you get in openhab.log ?

I use a shell script:

cmd="curl '' -H 'content-type: application/x-www-form-urlencoded; charset=UTF-8' --data 'grant_type=password&username=$1&password=$2&scope=offline_access&WebApiVersion=2&AppVersion=2.1.12'"
eval $cmd "2>/dev/null"

in my rule i call the script:

logInfo("Wolf","Token expired, requesting new token");
var String jsonToken =  executeCommandLine("bash@@/etc/openhab2/scripts/",5000)
token = transform("JSONPATH","$.access_token",jsonToken);