Trace displaces [object Object] , doesnt make call to backend

5317-screenshot-109.png

5316-screenshot-108.png

Hello APIGeeks,

Good Day !!!

I had implemented a nodejs proxy which intakes JSON from client and makes call to backend service. During request flow JS policy takecare of transforming incoming json payload, maps all the required parameters to back-end service supporting format.

During transformation, output of stringifyied object is displayed as [object Object].Due to this the nodejs doesnt makes call to backend.( as per my observation)

Attaching the trace and nodejs logs.FYI.. the same code is working locally.

JS policy(which does input parameter mapping)

var obj = {
	"products":JSON.stringify(this.products),
			"customer":JSON.stringify(this.customer),
			"ccinfo":JSON.stringify(this.ccinfo),
			"ordertotal":JSON.stringify(this.ordertotal)
	};


context.setVariable("request.content", JSON.stringify(obj));


NODE JS code.

var express = require('express');
var request = require('request');
var bodyParser = require('body-parser');
var apigee = require('apigee-access');


var app = express();
//app.use(bodyParser.json());


app.post('/', function(request, response) {
	console.log("request body1"+JSON.stringify(apigee.getVariable(request, 'request.content')))
	
	callToBackend(request, response, function(err, data) {


		if (!err){


			response.setHeader('Content-Type', 'application/json');
			
			response.send(data);
		}
		else {


			response.status(500).send("Server Error");
			return;
		}
	});


});


var callToBackend = function(mainreq, mainres, callback) {
	var jsonDataObj = apigee.getVariable(mainreq, 'request.content');
	
	console.log("request body"+JSON.stringify(jsonDataObj))


	var options = {


		url : "https://www.floristone.com/api/rest/flowershop/placeorder",
		body : jsonDataObj,
json:true,
		"headers" : {
			"content-type" : "application/json;charset=utf-8",
			"authorization" : "Basic NDE4ODQyOjB0RU5Fdw==",
			"Content-Length" :  "800"


		}


	};


	var req = request.post(options, function(err, res, body) {
console.log(body);
		if (!err && res.statusCode == '200')
			return callback(false, body);


		return callback(err, null);


	});


}


app.listen((process.env.PORT || 9001), function() {
	console.log("server Listening");
});




Please let me know if you need any more information. Appreciate you help.

Thanks,KP

0 2 233
2 REPLIES 2

trace-1500380083325.zip

Attaching Trace details.

Hi @Karthik Prabhu, From trace logs it is clear that the problem is with your Javascript policy "GetPayloadData". Can you please share the JS code of this policy?