CURL request fails with executeCommandLine in ECMA21/JSScripting/Javasript


I try to get a CURL request running which is successful on terminal.

Here is the JS code:

var curl1 = 'curl -X POST -k -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic THERIGHTXXXXXAPIKEY" -d \'{"priority": "warning", "model": { "cycles": 1, "frames": [{ "icon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAUklEQVQYlWNUVFBgYGBgYBC98uE/AxJ4rSPAyMDAwMCETRJZjAnGgOlAZote+fCfCV0nOmA0+yKAYTwygJuAzQoGBgYGRkUFBQZ0dyDzGQl5EwCTESNpFb6zEwAAAABJRU5ErkJggg==", "text": "HELLO!" } ], "sound": { "category": "notifications", "id": "cat" }}}\'';
var response1 = actions.Exec.executeCommandLine(Duration.ofSeconds(5), curl1);'Test send ' + response1);

And this is the error message - for me it says nothing…

==> /var/log/openhab/openhab.log <==

2023-04-13 21:57:24.853 [WARN ] [] - Failed to execute commandLine '[curl -X POST -k -H "Accept: application/json" -H "Content-Type: application/json" -H "Authorization: Basic THERIGHTXXXXXAPIKEY" -d '{"priority": "warning", "model": { "cycles": 1, "frames": [{ "icon": "data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAgAAAAICAYAAADED76LAAAAUklEQVQYlWNUVFBgYGBgYBC98uE/AxJ4rSPAyMDAwMCETRJZjAnGgOlAZote+fCfCV0nOmA0+yKAYTwygJuAzQoGBgYGRkUFBQZ0dyDzGQl5EwCTESNpFb6zEwAAAABJRU5ErkJggg==", "text": "HELLO!" } ], "sound": { "category": "notifications", "id": "cat" }}}']'

2023-04-13 21:57:24.877 [INFO ] [nhab.automation.script.ui.cf085708a0] - Test send null

Help very appreciated. I tried this (and other ways like sendHttpPostRequest) for multiple hours now and do not have any ideas left…

Thanks in advance!

For DSL rules arguments to the command ( which is curl ) need to be separated by commas. I would assume that it is the same for JS code as well.

From ( DSL ) docs:

// Space separated constants must be given as separate parameters as well
// e.g. path/to/your/ xyz fred.file
var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/your/", "xyz", "fred.file");

This topic was automatically closed 41 days after the last reply. New replies are no longer allowed.