I have some automation to sync photos from my smart phone to my “Gallery” on my server ( same host as Openhab)
Basically it goes like this..
Foldersync ( on Android phone) copies files to folder on Linux server
Foldersync at end of copy calls webhook ( php page) this triggers a switch item ON
Javascript calls PHP to extract meta data (EXIF) from files (js can’t do this) and post response
Javascript loops through data to rename/copy files to gallery location (via executeCommandLine)
javascript resets switch item to OFF
unfortunately the webhook only supports header “application/json” so I can’t update switch directly.
Q. Can I send a json list of files back to Openhab to process directly via HTTP?
note list could large eg 500+ entries.
error when webhook sent:
2025-08-10 16:16:06.452 \[ERROR\] \[internal.JSONResponseExceptionMapper\] - Unexpected exception occurred while processing REST request.
com.google.gson.JsonSyntaxException: java.lang.IllegalStateException: Expected BEGIN_OBJECT but was STRING at line 1 column 1 path $
See https://github.com/google/gson/blob/main/Troubleshooting.md#unexpected-json-structure
at com.google.gson.internal.bind.ReflectiveTypeAdapterFactory$Adapter.read(ReflectiveTypeAdapterFactory.java:520) \~\[?:?\]
at com.google.gson.Gson.fromJson(Gson.java:1361) \~\[?:?\]
at com.google.gson.Gson.fromJson(Gson.java:1262) \~\[?:?\]
at com.google.gson.Gson.fromJson(Gson.java:1199) \~\[?:?\]
There might be a node module you could install and use to do this.
A quick search shows at heart three out there. I’m sure there are more.
But there’s nothing wrong with using an external call either.
There is a Webhook binding on the marketing leave that might be more flexible.
I didn’t see why not. Use a String Item and use an http post on the item update endpoint (see MainUI → Developer Tools → API Explorer for details). That accepts plain text or JSON.
There is also an API endpoint using POST to run a rule directly without going through an Item. That takes JSON too but requires a specific type of JSON which may not work with the JSON you have.
oh I didn’t see this this could simiplfy the process,
I’m not really interested in the incoming args but just in-case , how do you get args from the called rule? ie how do I read the args from the HTTP/ POST call?
If you are using anything other than Ruels DSL, you can set the rule ID when you define it. If you are using Rules DSL in text, That’s one of the many things Rules DSL in .rules files cannot do. You can create a managed rule that uses Rules DSL in the actions even, but in a file you are out of luck.
Note, the ID of a rule in a .rules file is at least predictable. It’s going to be the name of the file and it’s position in the file. For example the third rule in the file foo.rules will be “foo-3”.
In JS it depends on whether you are using rule builder of JSRule. In rule builder you set the rule ID in the call to build():
Rule are completed by calling .build(name, description, tags, id) , all parameters are optional and reasonable defaults will be used if omitted.
If using JSRule, it’s one of the properties you set in the Map you pass to JSRule. Example from the docs:
var email = "juliet@capulet.org"
rules.JSRule({
name: "Balcony Lights ON at 5pm",
description: "Light will turn on when it's 5:00pm",
triggers: [triggers.GenericCronTrigger("0 0 17 * * ?")],
execute: (event) => {
// Equivalent to items.BalconyLights.sendCommand("ON")
items.getItem("BalconyLights").sendCommand("ON");
actions.NotificationAction.sendNotification(email, "Balcony lights are ON");
},
tags: ["Balcony", "Lights"],
id: "BalconyLightsOn"
});
The id in that rule is “BalconyLightsOn”.
For managed rules you have the opportunity to set the Rule ID when you first create it.