API rules runnow: How to access payload?

Continuing the discussion from API rules runnow: What is the payload for?:

Hi,
a pretty old thread but this is the same question for my problem.

I want to execute a file based JS Rule and want to handover some parameters.
For me and ChatGPT it wasn’t possible to figure out how I can access the request body.

So direct access of the parameter additionalProp1 like in the linked thread is not possible.
Can somebody help here?

For file based rules the passed in variables are in event.raw.

Bus this is also always empty

Curl Request:

curl -X 'POST' \
'http://192.168.178.32:8080/rest/rules/1-c22e3e55-27c4-4a14-a520-d7bc35ace206/runnow' \
-H 'accept: */*' \
-H 'Content-Type: application/json' \
-H 'Authorization: Bearer eyJraWQiOm51bGwsImFsZyI6IlJTMjU2In0.eyJpc3MiOiJvcGVuaGFiIiwiYXVkIjoib3BlbmhhYiIsImV4cCI6MTc2NDc4OTc2NCwianRpIjoiLWJieEVSOUlwUnRhRjVKaW9Mc19ydyIsImlhdCI6MTc2NDc4NjE2NCwibmJmIjoxNzY0Nzg2MDQ0LCJzdWIiOiJhZG1pbiIsImNsaWVudF9pZCI6Imh0dHA6Ly8xOTIuMTY4LjE3OC4zMjo4MDgwIiwic2NvcGUiOiJhZG1pbiIsInJvbGUiOlsiYWRtaW5pc3RyYXRvciJdfQ.b1dtD8J1E4K3pODMmmsXV9cS3hNvb8u6bSEnmowKRJi1N1HCG6xNNCt3i1F5PBUNbYZj7nfvppS0Hl6l94bzchenYAjki7anu2w5hvIl5em9naNt24FP0sjlDJ8pAUduoruUnTyK8GGYiEG6DHUvHhCjxcnOZCWQvMWtes6UfsaYGlExZ_nGtIyZTIMS5YzLoWqaojE9VGEiYebRAp5g0PKZo919XofMt2fQETRhWhpGSrZF9qx5Se4Drxl-iZzcue2PtyXZL5PZ61C6H_rJ5YRwvRDZMYv2SITajuj0jyeG-oqfhx811yk9baRHtBQjUiVVa8U3QDFNVofD0VsfTw' \
-d '{
"additionalProp1": "hallo",
"additionalProp2": {},
"additionalProp3": {}
}'

openhab log output:

2025-12-03 19:23:20.795 \[INFO \] \[omation.script.file.deltaBetween2.js\] - Input JSON: {
“raw”: {}
}

Snappshot of the Rule to test:

rules.JSRule({
  name: "1",
  description: "Executes deltaBetween using JSON from an Item due to OH4 REST bug",
  execute: (event) => {
    console.log("DeltaBetween: Rule started");
	console.log("Input JSON:", event);

I do not know how to pass arguments through the REST API so I cannot comment whether the curl command is correct. It looks like it might be correct but :person_shrugging: .

From the docs:

raw all Original contents of the event including data passed from a calling rule N/A

I don’t use file based rules, but raw is the original Java Object passed to the rule without any manipulation by the library. So it will be the same for UI and file based.

Using the REST API I passed

{
  "additionalProp1": "foo",
  "additionalProp2": "bar",
  "additionalProp3": "baz"
}

To call a script called toCall containing the following:

console.info('Type is ' + event.type);
console.info('raw ' + event.raw);
console.info('raw.additionalProp1 ' + event.raw.additionalProp1);

which generated

2025-12-03 11:53:42.490 [INFO ] [b.automation.jsscripting.rule.toCall] - Type is undefined
2025-12-03 11:53:42.493 [INFO ] [b.automation.jsscripting.rule.toCall] - raw {additionalProp1=foo, additionalProp3=baz, ruleUID=toCall, additionalProp2=bar}
2025-12-03 11:53:42.494 [INFO ] [b.automation.jsscripting.rule.toCall] - raw.additionalProp1 foo

Note that the exact same event Object is now passed into UI based rules from OH 5.1 M1 forward, so this is the exact same thing one would see from a file based rule.

Note: you should always set the id of the rule so it’s both meaningful and doesn’t change every time you edit the file.

You do not mention which version of OH you are on. If it’s before OH 5 the answer may be you can’t do this. Sometime during OH 4’s development adding these passed in arguments were added to the event Object for file based rules. Before that though it was not supported.

ok Openhab version was the trick. I updated my test instance to version 5 M2 and this is working.
I’m still a bit wondering why this functions is not already working in 4 but ok.

Thanks also for the hint with the rule id … was not aware of it. Make it’s a lot more easier to call the rule over rest api :smiley:

Thank you @rlkoshak

Because it wasn’t implemented yet.

Not many files based rules users do this as it’s much easier and more flexible to build a personal library instead.