I am a newby in Node js, after hit HubSpot api through node js by using node-rest-middleware am getting below kind of response. Why?
<Buffer 7b 22 76 69 64 22 3a 35 2c 22 63 61 6e 6f 6e 69 63 61 6c 2d 76 69 64 22 3a 35 2c 22 6d 65 72 67 65 64 2d 76 69 64 73 22 3a 5b 5d 2c 22 70 6f 72 74 61 ... >
Here is my snippet please take a look
var args = {
data: formData,
headers:{"Content-Type": "application/json"}
};
client.post(hubURL, args, function(data,response) {
// parsed response body as js object
console.log(data, "data in client post");
});
and formData is a proper valid json what am doing wrong
updated here is the snapshot
I am a newby in Node js, after hit HubSpot api through node js by using node-rest-middleware am getting below kind of response. Why?
<Buffer 7b 22 76 69 64 22 3a 35 2c 22 63 61 6e 6f 6e 69 63 61 6c 2d 76 69 64 22 3a 35 2c 22 6d 65 72 67 65 64 2d 76 69 64 73 22 3a 5b 5d 2c 22 70 6f 72 74 61 ... >
Here is my snippet please take a look
var args = {
data: formData,
headers:{"Content-Type": "application/json"}
};
client.post(hubURL, args, function(data,response) {
// parsed response body as js object
console.log(data, "data in client post");
});
and formData is a proper valid json what am doing wrong
updated here is the snapshot
Share Improve this question edited Aug 26, 2015 at 4:30 The Mechanic asked Aug 26, 2015 at 4:20 The MechanicThe Mechanic 2,3291 gold badge28 silver badges37 bronze badges 4- Could not find the middleware in npm. Try utf8 encoding the buffer. Or, just use npmjs./package/request – Swaraj Giri Commented Aug 26, 2015 at 4:23
- @SwarajGiri unable to use request middleware. I haven't see how to hit rest api through request. here is the link npmjs./package/node-rest-client – The Mechanic Commented Aug 26, 2015 at 4:24
- Start by converting the buffer to a string and see what's inside. That might give you a hint – Amit Commented Aug 26, 2015 at 4:29
- updated my answer, this should work. – Mritunjay Commented Aug 26, 2015 at 4:33
3 Answers
Reset to default 4The data
you are getting is a Buffer. Try converting it to string like bellow.
if(Buffer.isBuffer(data)){
data = data.toString('utf8');
}
console.log(data);
This is data formatting issue, you are getting data in Buffer format and you want it in String format.
You can explicitly do the conversion.
You can use toString() of the Buffer, which will convert Buffer format into String format. Refer
var yourStringData = data.toString('utf8');
The Buffer should be converted to a String
client.post(baseUri + "tradingpartners/",args, function (data, response) {
// parsed response body as js object
console.log(data.toString('utf8'));
});