Curl script returning Null

I’m trying to get a curl script working, but I can’t get OH2 to return anything at all.

In 2.0.0b3, and the the latest snapshot, it fails so I feel like I’m missing something crucial. I have installed the exec and http bindings through paperUI. As well as a few transformations fwiw.


String test_Payload { exec="<[C:/Openhab/OpenHAB2/conf/scripts/*?))]" }

curl -X POST -H "host:" -H "Content-Type: application/json; charset=utf-8" -H "Authorization: bearer 9cb01305-xxxx-xxxx-xxxx-614f04749838" -H "d: """ -H "Cache-Control: no-cache" -H "Postman-Token: 7f208f85-2c1f-96ce-2ca7-033fab5b83fe" -d '' "


rule TestRule
Item test_Payload received update
logInfo(“Sensor”, “Test Sensor Payload arrived…”) //To tell me the script fired OK
logInfo(“Sensor”, test_Payload.state.toString) //To show the curl string in the log

All of this returns only

[INFO ] [clipse.smarthome.model.script.Sensor] - Test Sensor Payload arrived…
[INFO ] [clipse.smarthome.model.script.Sensor] -

I’ve tried using executeCommandLine and the result is the same.

If I simplify my test curl to something different like curl The result is also the same.

The curl script is part of a larger rule which has some JSON transformations,. This throws an error about how the JSON string cannot be null or empty, hence my stripped back test to get it figured out. I’m trying this on a Win10x64 machine right now, but have similar results from my Pi3 running raspbian.

I should also add, that running the curl script in Windows (using Cygwin) works fine, as does doing the same on OSX (terminal) and my Pi3 (via ssh).

Anyone got any tips?

Does the script work as expected, if you call it from command line? I think, there is a missing quotation mark (") at the end of the curl line (could be copy-paste issue, though)

Did you use the executeCommandLine with the timeout and then log the results?

val String results = executeCommandLine("my script", 5000)
logInfo("curl", results)

Ok, so if I use the timeout and the simple curl string then I get the expected log result. Thanks.

However, if I use the longer string

val String results = executeCommandLine("curl curl@@--silent@@-X@@POST@@-H@@""@@-H@@"Content-Type:@@application/json;@@charset=utf-8"@@-H@@"Authorization:@@bearer@@9cb01305-b6d7-47c2-ada9-614f04749838"@@-H@@"d:@@"""@@-H@@"Cache-Control:@@no-cache"@@-H@@"Postman-Token:@@7f208f85-2c1f-96ce-2ca7-033fab5b83fe"@@-d@@''@@""", 5000)
logInfo("curl", results)

I get the info/error:

[INFO ] [] - executed commandLine '[curl, --silent, -X, POST, -H]'
[ERROR] [.script.engine.ScriptExecutionThread] - Rule 'TestRule': An error occured during the script execution: The name 'host' cannot be resolved to an item or type.

This happens whether I use spaces, or replace them with @@ as mentioned in other similar topics.

You need to escape quotes(") that appear inside of quotes using a backslash. Otherwise it thinks the String has ended and tries to treat the “host” part as a variable.

"curl curl --silent -X POST -h \"host: ... .com\" -H \Content-Type:...utf-8\" ..."

I’m pretty sure you don’t need the “@@” when using executeCommandLine.

Thanks Rich,

Nearly there… I can escape the string and it appears to fire, but I get no log, nor the full curl returned in the info.

[INFO ] [] - executed commandLine 'curl --silent -H “Host:” -X POST -H “Content-Type: application/json; charset=utf-8” -H “Authorization: bearer 9cb01305-b6d7-47c2-ada9-614f04749838” -H "d: ’

It appears to finish the curl early, and OH doesn’t log anything at all. I’ll keep trying to figure out how to escape the -H d: portion of the script as it’s different to the rest but I’m really only guessing.

Try escaping the single quotes as well.


It was always failing with the single quotes at the end of the curl ...-d '' \"http://myt...

This has to read ...-d {} \"http://myt...

My theory is that the single quotes were just to say to post nothing to the following address. However looking around all the references I could find to a similar technique used curly brackets.

Now to incorporate it back into my rule…

Thanks Rich.