04-12-2023 12:08 PM
Hello,
I created a folder rule that executes a JS script.
In this script, i'm trying to POST the document's ID in ODOO api using the following code:
var nid = document.properties['cm:nid'];
var url = "http://localhost../api/alfresco/create";
var data = { "node_id": nid };
var headers = {
"Content-Type": "application/json",
"Accept": "application/json"
};
var http = new Packages.org.apache.commons.httpclient.HttpClient();
var post = new Packages.org.apache.commons.httpclient.methods.PostMethod(url);
post.setRequestEntity(new Packages.org.apache.commons.httpclient.methods.StringRequestEntity(JSON.stringify(data), "application/json", "UTF-8"));
for (var key in headers) {
if (headers.hasOwnProperty(key)) {
post.addRequestHeader(key, headers[key]);
}
}
try {
var status = http.executeMethod(post);
logger.log("API response status: " + status);
logger.log("API response body: " + post.getResponseBodyAsString());
} catch (ex) {
logger.log("Error sending POST request to API: " + ex);
} finally {
post.releaseConnection();
}I tested this script in Javascript Console it works good, but when i try to execute it when adding a document, it shows the following error:
What might be the problem here? Am I using the wrong packages?
05-01-2023 12:10 AM
Please check alfresco log. There you will get idea why it is failing.
Explore our Alfresco products with the links below. Use labels to filter content by product module.