POST alfresco data to ODOO ERP

cancel
Showing results for 
Search instead for 
Did you mean: 
imanez1
Active Member II

POST alfresco data to ODOO ERP

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:

Sans titre.png

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

1 Reply
sanjaybandhniya
Intermediate

Re: POST alfresco data to ODOO ERP

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