cancel
Showing results for 
Search instead for 
Did you mean: 

POST alfresco data to ODOO ERP

imanez1
Confirmed Champ
Confirmed Champ

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:

image

What might be the problem here? Am I using the wrong packages?

1 REPLY 1

sanjaybandhaniya
Elite Collaborator
Elite Collaborator

Please check alfresco log. There you will get idea why it is failing.