Tag Archives: http-post

How to submit a POST request to Apache Syncope API in node.js?

Salam (means Hello) :)

In my node.js application, I am trying to add a user to Apache Syncope via its RESTful API. Apache Syncope is installed on a remote VPS and this article demonstrate this process in a PHP environment. here is what I did in my node.js application:

http.createServer(onRequest).listen(80);

function onRequest (request, response) {
    var options = {
        hostname: MY_VPS_IP,
        port: 8080,
        path: '/syncope/rest/user/create.json',
        auth: 'admin:password',
        method: 'POST'
    };
    var data = {an: 'object', of: 'new', user: 'data' };

    var req=http.request(options, function(res) {
        var body;
        res.on('data', function (chunk) {
            body += chunk;
        });
        res.on('end', function () {
            response.writeHead(200, { 'Content-Type': 'text/html' });
            response.end(body, 'utf-8');
        });
    });
    req.end(JSON.stringify(data));
}

The response of Apache Syncope is a 415 error (css styles omitted):

undefined
<html>
<head><title>Apache Tomcat/7.0.42 - Error report</title>
</head>
<body><h1>HTTP Status 415 - </h1>
<HR size="1" noshade="noshade">
<p><b>type</b> Status report</p>

<p><b>message</b> <u></u></p>

<p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the
    requested resource for the requested method.</u></p>
<HR size="1" noshade="noshade">
<h3>Apache Tomcat/7.0.42</h3></body>
</html>

How to submit a POST request to Apache Syncope API in node.js?

Salam (means Hello) :)

In my node.js application, I am trying to add a user to Apache Syncope via its RESTful API. Apache Syncope is installed on a remote VPS and this article demonstrate this process in a PHP environment. here is what I did in my node.js application:

http.createServer(onRequest).listen(80);

function onRequest (request, response) {
    var options = {
        hostname: MY_VPS_IP,
        port: 8080,
        path: '/syncope/rest/user/create.json',
        auth: 'admin:password',
        method: 'POST'
    };
    var data = {an: 'object', of: 'new', user: 'data' };

    var req=http.request(options, function(res) {
        var body;
        res.on('data', function (chunk) {
            body += chunk;
        });
        res.on('end', function () {
            response.writeHead(200, { 'Content-Type': 'text/html' });
            response.end(body, 'utf-8');
        });
    });
    req.end(JSON.stringify(data));
}

The response of Apache Syncope is a 415 error (css styles omitted):

undefined
<html>
<head><title>Apache Tomcat/7.0.42 - Error report</title>
</head>
<body><h1>HTTP Status 415 - </h1>
<HR size="1" noshade="noshade">
<p><b>type</b> Status report</p>

<p><b>message</b> <u></u></p>

<p><b>description</b> <u>The server refused this request because the request entity is in a format not supported by the
    requested resource for the requested method.</u></p>
<HR size="1" noshade="noshade">
<h3>Apache Tomcat/7.0.42</h3></body>
</html>