I need some assistance with my web application. Whenever I try to create a record by sending data to the API endpoint, it always returns a 400 bad request error on the front end. Surprisingly, when I tested the same request in Insomnia, everything worked perfectly fine. Can someone help me figure out why this issue is occurring?
Here's the code snippet:
async createEvent() {
const requestBody = {
userId: this.#userId,
eventName: this.#name,
eventDate: this.#date
}
const createEventResponse = await fetch(`http://localhost:3001/event/create`, {
method: "POST",
headers: {
"Accept": "application/json",
"Content-Type": "application/json"
},
body: JSON.stringify(requestBody)
});
const { message } = await createEventResponse.json();
if (createEventResponse.status === 200) {
return {
flag: true,
message
}
} else if (createEventResponse.status ==- 401) {
return {
flag: false,
message
}
}
}