API Access with curl - GET okay - POST doesnt work
Hey guys,
nice piece of software that you've created with lets chat - congrats. Currently i have it set up in a local vm to play with, but hope to get started with the rest of our little crew soon.
Besides other things i try to figure out, there is this problem with POST-API calls. I couldn't find an example so i tried this:
GET Messages of a room works:
curl --user NTVhZjgyZmQ1YmZhZmYyMzI0ZGMwYTZiOjdjMWEzZjczZDk0MWI5ZjAyYjgwZDFiZDRiMGJmYmE2YTg5ZTlmMzJmOTQ4NTk3MQ==:abc --request GET http://192.168.127.130:5000/rooms/55af83545bfaff2324dc0a6c/messages
[{"id":"55af95a7860b975f2406f5c9","text":"https://media1.giphy.com/media/d89VuJ4GflFfO/200w.gif","posted":"2015-07-22T13:07:51.112Z","owner":"55af82fd5bfaff2324dc0a6b","room":"55af83545bfaff2324dc0a6c"},.....]
But trying to send a message via POST does not work:
curl -k --user NTVhZjgyZmQ1YmZhZmYyMzI0ZGMwYTZiOjdjMWEzZjczZDk0MWI5ZjAyYjgwZDFiZDRiMGJmYmE2YTg5ZTlmMzJmOTQ4NTk3MQ==:abc -d '{"text": "test"}' --request POST http://192.168.127.130:5000/rooms/55af83545bfaff2324dc0a6c/messages
Bad Request
This is the error thrown at the console this moment:
{ [ValidationError: Message validation failed]
stack: 'Error\n at MongooseError.ValidationError (/daten/install/lets-chat/node_modules/mongoose/lib/error/validation.js:22:16)\n at model.Document.invalidate (/daten/install/lets-chat/node_modules/mongoose/lib/document.js:1162:32)\n at /daten/install/lets-chat/node_modules/mongoose/lib/document.js:1037:16\n at validate (/daten/install/lets-chat/node_modules/mongoose/lib/schematype.js:653:7)\n at /daten/install/lets-chat/node_modules/mongoose/lib/schematype.js:681:9\n at Array.forEach (native)\n at SchemaString.SchemaType.doValidate (/daten/install/lets-chat/node_modules/mongoose/lib/schematype.js:658:19)\n at /daten/install/lets-chat/node_modules/mongoose/lib/document.js:1035:9\n at process._tickCallback (node.js:419:13)',
message: 'Message validation failed',
name: 'ValidationError',
errors:
{ text:
{ [ValidatorError: Path `text` is required.]
properties: [Object],
stack: 'Error\n at MongooseError.ValidatorError (/daten/install/lets-chat/node_modules/mongoose/lib/error/validator.js:25:16)\n at validate (/daten/install/lets-chat/node_modules/mongoose/lib/schematype.js:652:13)\n at /daten/install/lets-chat/node_modules/mongoose/lib/schematype.js:681:9\n at Array.forEach (native)\n at SchemaString.SchemaType.doValidate (/daten/install/lets-chat/node_modules/mongoose/lib/schematype.js:658:19)\n at /daten/install/lets-chat/node_modules/mongoose/lib/document.js:1035:9\n at process._tickCallback (node.js:419:13)',
message: 'Path `text` is required.',
name: 'ValidatorError',
kind: 'required',
path: 'text',
value: undefined } } }
I receive similiar output when trying to create or room, like "room validation failed" and that slug/name is required. So it seems like curl doesn't send the data-part quite right, but this is the only way i know.
What am i doing wrong and/or what's your recommended way of sending messages to lets-chat via command-line?
nevermind i just had to complete the command line with this option and it worked:
-H 'Content-Type: application/json'
@dudleyperkins hah glad to hear :P