0

createJsonClient to post my data to a restify server like

console.log(typeof payload); // string
payload = JSON.parse(payload).Body;
console.log(payload); //object

client.post('/sqs', payload, function (err, req, res, obj) {
if (err) 
   callback(err, null);
else {
   console.log(obj);
}
});

But I'm getting

{ [InternalError: Unexpected token o]\n  message: 'Unexpected token o',\n  statusCode: 500,\n  body: { code: 'InternalError', message: 'Unexpected token o' },\n  restCode: 'InternalError',\n  name: 'InternalError' }

The payload is a valid JSON object after JSON.parse, How do post an object in restify.createJsonClient ?

Kenichi Shibata
  • 148
  • 2
  • 11

1 Answers1

1

your payload is an object, while you need to send JSON string, so just remove line

payload = JSON.parse(payload).Body;

from restify docs:

client.post('/foo', { hello: 'world' }, function(err, req, res, obj) {
  assert.ifError(err);
  console.log('%d -> %j', res.statusCode, res.headers);
  console.log('%j', obj);
});
Darko Rodic
  • 1,010
  • 3
  • 10
  • 27