API request body completely empty
Unanswered
Standard Chinchilla posted this in #help-forum
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
@Standard Chinchilla 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?
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);
});
}
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
Standard ChinchillaOP
omg
thank you so much