Magento 2 Get Raw Request Data in Controller

If you want to get all the data which are sent outside Magento or from POSTMAN to the Magento controller and the format of the body is Raw then you can not get data using getParams() in the Magento 2

If you want to get this raw request data in the Magento controller, you can get it using the following code.

$this->getResponse()->getRawBody()

Here is the screenshot of how you send the data from POSTMAN or any third-party API to the Magento 2 controller.

Magento Raw Data in Controller

Extra Note: If you want to get all the body data which are sent from the POSTMAN to your core PHP project then the following code will help you

$jsonData = json_decode(file_get_contents("php://input"), true);

Hope this will help Magento and PHP developers 🙂

You can review our previous blog post to solve this issue of Session size exceeded allowed session max size of 256000