Hi,
i want to use a rule for creating annotations with bearer token.
first i tried this via shell which works:
curl -H "Authorization: Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx" -H "Content-Type: application/json" -X POST \-d '{"tags":["test"],"text":"your description"}' http://192.168.2.244:3000/api/annotations
im using actually oh 4.1.1. and want to do the same by rule without using exec.
so i tried to do same via javascript rule with sendHttpPostRequest but then i had problems:
var headers={"Authorization": "Bearer xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx", "Content-Type": "application/json"};
var url = "http://192.168.2.244:3000/api/annotations"
var content = '{"tags":["test"],"text":"your description"}'
var HTTP=Java.type("org.openhab.core.model.script.actions.HTTP");
var result=HTTP.sendHttpPostRequest(url,"application/json", content,headers)
console.log(result);
can anyone help me to get out my problem how to use HTTP.sendHttpPostRequest successfully for this?
actually it tells:
2024-01-14 14:16:09.760 [ERROR] [internal.handler.ScriptActionHandler] - Script execution of rule with UID '51c0f0ece4' failed: org.graalvm.polyglot.PolyglotException: TypeError: invokeMember (sendHttpPostRequest) on org.openhab.core.model.script.actions.HTTP failed due to: no applicable overload found (overloads: [Method[public static java.lang.String org.openhab.core.model.script.actions.HTTP.sendHttpPostRequest(java.lang.String,java.lang.String,java.lang.String,java.util.Map,int)], Method[public static java.lang.String org.openhab.core.model.script.actions.HTTP.sendHttpPostRequest(java.lang.String,java.lang.String,java.lang.String,int)], Method[public static java.lang.String org.openhab.core.model.script.actions.HTTP.sendHttpPostRequest(java.lang.String,java.lang.String,java.lang.String)], Method[public static java.lang.String org.openhab.core.model.script.actions.HTTP.sendHttpPostRequest(java.lang.String,int)], Method[public static java.lang.String org.openhab.core.model.script.actions.HTTP.sendHttpPostRequest(java.lang.String)]], arguments: [http://192.168.2.244:3000/api/annotations (String), application/json (String), {"tags":["test"],"text":"your description"} (String), DynamicObject<JSOrdinary>@18281ef0 (DefaultLayout)])