I am a beginner at web development and I am trying to use Postman to send a POST request to one of my application's APIs.I am using the Next.JS framework to build my website.
Here is my API:
import type { NextApiRequest, NextApiResponse } from "next"export default async ( req: NextApiRequest, res: NextApiResponse,) => { const userData = JSON.parse(req.body) res.status(200).json(userData)}I simplified my API until I caught the error, and I believe that it is related to the JSON.parse(req.body) line.
This is a print of the data that I used to test the API on Postman
I get the following error:
SyntaxError: Unexpected number in JSON at position 1at JSON.parse (\u003canonymous\u003e)at __WEBPACK_DEFAULT_EXPORT__ (webpack-internal:///(api)/./pages/api/login.ts:9:27)Previously, I used this API to authenticate users, and everything worked fine, except when I tried to insert data into the body of a Postman POST request.
Can someone help me? I have no idea what to do.