I’ve got my own REST API running and using Postman I’m able to create a record like this:
I am having trouble configuring this in AppGyver:
I get this error:
The code I have in the API is this:
router.post("/:id/messages", (req, res) => {
const { id } = req.params;
const msg = req.body;
if (!msg.lesson_id) {
msg["lesson_id"] = parseInt(id, 10);
}
Lessons.findById(id)
.then(lesson => {
if (!lesson) {
res.status(404).json({ message: "Invalid Id" });
}
// check for required fields
if (!msg.sender || !msg.text) {
res.status(400).json({ message: "Must provide sender and text" });
}
Lessons.addMessage(msg, id)
.then(message => {
if (message) {
res.status(200).json(message);
}
})
.catch(err => {
res.status(500).json({ message: "Failed to add message" });
})
})
.catch(error => {
res.status(500).json({ message: "Error finding lesson" });
})
});
Any ideas what I am doing wrong?