Reputation: 2329
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
Upvotes: 4
Views: 5108
Reputation: 80
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'));
});
Upvotes: 0
Reputation: 25882
The 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);
Upvotes: 4
Reputation: 4691
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');
Upvotes: 1