Issue
So I have been given an API to which I need to send a post request to create a task within a list, but when I try to send the request, I get the following error (I am trying it in postman).
The following is the schema of a post request body I need to send to the API, and the image is the request I am sending with the postman (I need to use the x-www-form-urlencoded because otherwise, it is not working)
{
title: { type: String,required:true},
description: String,
done:Boolean,
date: { type: Date, default: Date.now },
list:{
type: Schema.ObjectId,
ref: 'List'
}
So can you please help me with this? I get the following error.
Cast to ObjectID failed for value \"Daily Tasks\" at path \"list\"
Solution
The API is expecting you to pass the id of a List, not its name. It's probably expecting you to do an other API call before to get that id.
It should look like this: "507f1f77bcf86cd799439011"
Additionally, you can look at the documentation of MongoDB for information about the ObjectId format: https://docs.mongodb.com/manual/reference/method/ObjectId/
Answered By - qventura
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.