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)
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.
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)
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 http://my.ip.fi", 2000)
logInfo( "test123", "my IP is : {}", responseSample )
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.