CURL request fails with executeCommandLine in ECMA21/JSScripting/Javasript

Hi,

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" }}}\' https://192.168.13.161:4343/api/v2/device/notifications';
var response1 = actions.Exec.executeCommandLine(Duration.ofSeconds(5), curl1);
console.info('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 ] [rg.openhab.core.io.net.exec.ExecUtil] - 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" }}}' https://192.168.13.161:4343/api/v2/device/notifications]'

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!
HFM

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/script.sh xyz fred.file
var ScriptResponse = executeCommandLine(Duration.ofSeconds(60), "path/to/your/script.sh", "xyz", "fred.file");

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