Accessing raw body data from POST endpoint
Answered
Yellowfin tuna posted this in #help-forum
Yellowfin tunaOP
Hello, I want to ask for help regarding accessing raw body data from within POST handler in Nextjs v14 app. I need to get the raw data because i need make verification of sent data (compute hash) — i am building interactive endpoint for Slack (docs for Slack verification here: https://api.slack.com/authentication/verifying-requests-from-slack).
I found a solution for Nextjs v13 using:
export const config = {
api: {
bodyParser: false,
},
};
But this seems to not working in v14.
Do you have some ideas?
Thank you in advance🙏
I found a solution for Nextjs v13 using:
export const config = {
api: {
bodyParser: false,
},
};
But this seems to not working in v14.
Do you have some ideas?
Thank you in advance🙏
Answered by B33fb0n3
you can access the raw body by getting it via the
text() function like this:export async function POST(request: Request) {
const rawBody = await request.text();
// todo do something with rawBody
}4 Replies
@Yellowfin tuna Hello, I want to ask for help regarding accessing raw body data from within POST handler in Nextjs v14 app. I need to get the raw data because i need make verification of sent data (compute hash) — i am building interactive endpoint for Slack (docs for Slack verification here: https://api.slack.com/authentication/verifying-requests-from-slack).
I found a solution for Nextjs v13 using:
export const config = {
api: {
bodyParser: false,
},
};
But this seems to not working in v14.
Do you have some ideas?
Thank you in advance🙏
you can access the raw body by getting it via the
text() function like this:export async function POST(request: Request) {
const rawBody = await request.text();
// todo do something with rawBody
}Answer
@Yellowfin tuna solved?
Yellowfin tunaOP
Sorry for not answering. Yeah it works 👍 thx 😉