-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
How can i get the raw body in api routes for webhook? #9541
Comments
Please include a minimal reproduction of the issue, and we will attend to it. |
Thanks for responding, quickly! With the routes approach I tried: import {
MedusaRequest,
MedusaResponse,
ProductService,
} from "@medusajs/medusa";
export const POST = async (req: MedusaRequest, res: MedusaResponse) => {
res.status(200);
console.log("Body", req.body);
console.log("Raw Body:", req.rawBody);
}; and middleware as: import {
MedusaNextFunction,
MedusaRequest,
MedusaResponse,
MiddlewaresConfig,
} from "@medusajs/medusa";
import { raw } from "body-parser";
export const config: MiddlewaresConfig = {
routes: [
{
method: ["POST", "PUT"],
matcher: "/webhooks/*",
bodyParser: false,
middlewares: [raw({ type: "application/json" })],
},
],
}; But i got rawData as undefined. I want to get the rawData. |
If you want to access the raw body as It would look like this:
I believe you can then omit Can you give this a shot and let me know if it works? |
I had tried it before, but i tried again but unfortunately, it doesn't work :/ Do you have another solution? |
What payment provider is this? |
I am using Cashfree Payment. I didn't find any working plugin for it. |
Can you let me know what you are seeing with Also, if you want me to test this out, please provide a small reproduction in a repository. |
Here's the repo: |
Great, I'll check it out. QQ: Is there a reason you haven't started with the preview version of Medusa 2.0? If you can, I would recommend that to avoid an upgrade in the near term. |
It's because i already have built my entire website. I am working on the implementing the payment gateway. Is it production ready yet? I heard it goes production ready on 23rd or something. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 3 days. |
This issue is stale because it has been open 30 days with no activity. Remove stale label or comment or this will be closed in 3 days. |
@balramxyadav Did you get a solution for it? |
I want to implement a webhook for a custom payment gateway, but no matter what I do, it doesn't work. I can never get the req.rawBody that the webhook requires. When I tried it with a normal Express server (sepreate from medusa), it worked perfectly, but for some reason, it's not working in Medusa. I tried the Express approach that didn't work, and then followed the routes approach Medusa recommends, and set up middleware as described here: https://docs.medusajs.com/development/api-routes/create#parse-webhook-body-parameters. But I still can't get the rawBody. Can someone help?
The text was updated successfully, but these errors were encountered: