API request body completely empty
Unanswered
Standard Chinchilla posted this in #help-forum
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Standard ChinchillaOP
The JSON.stringify(req) just returns {}.
I'm using postman to post a body, but yeah its like its not receiving anything at all, although the endpoint IS being hit. Anyone know how I can fix this?
I'm using postman to post a body, but yeah its like its not receiving anything at all, although the endpoint IS being hit. Anyone know how I can fix this?
export async function POST(req: NextApiRequest, res: NextApiResponse) {
const sgMail = require("@sendgrid/mail");
console.log("request is " + JSON.stringify(req));
const emailData: sendGridEmailDTO = req.body;
console.log("emailData is " + JSON.stringify(emailData));
sgMail
.send(emailData)
.then(() => {
console.log("Email sent");
})
.catch((error: any) => {
console.log("THERE WAS AN ERROR");
console.log("error is " + JSON.stringify(error));
console.error(error);
});
}
3 Replies
![Avatar](https://cdn.discordapp.com/avatars/484037068239142956/44415017de6fed2ccd5d44b4b2051ac0.webp?size=256)
joulev
1. it's not
2. to get json body: https://nextjs.org/docs/app/building-your-application/routing/router-handlers#request-body
req: NextApiRequest, res: NextApiResponse
. The syntax is completely different now https://nextjs.org/docs/app/building-your-application/routing/router-handlers2. to get json body: https://nextjs.org/docs/app/building-your-application/routing/router-handlers#request-body
![Avatar](https://cdn.discordapp.com/embed/avatars/3.png)
Standard ChinchillaOP
omg
thank you so much