I have defined a custom remote method in loopback trying to post some data.
Here is the code of the methode definition:
Workout.prototype.greet = function(userId, exercises, cb) {
cb(null, userId + ' ' + this.id);
}
Workout.remoteMethod('prototype.greet', {
accepts: [{arg: 'userId', type: 'string', required: true, description:"MyUserId for who created the challenge", http: { source: 'query' }},
{arg: 'exercises', type: 'array', required: true, description:"Array of exercises which should be added", http: { source: 'body' }}],
returns: {arg: 'greeting', type: 'object'},
});
When posting data with an empty array in exercises everything works fine see:Working without data. But when I insert any information into the array I get an error see: Not Working with data
Hope somebody can help me. Thank you!
You see that error because you send malformed JSON. You omit quotation marks around id. It should look like this:
["id": "1"]