I have a POST endpoint that receives a JSON payload.

I'm using the Magento\Framework\App\Request\Http class to try and retrieve my POST data.

If I run $data = $this->request->getPost();, then $data will be empty.

However if I run $data = file_get_contents('php://input'); I am able to view my JSON payload as a string.

Is there a way to grab this natively through Magento?

FWIW I'm testing this through a rest/V1 endpoint through Postman.
This is a POST request with a chunk of (valid) JSON data in the raw data type.

  • try $this->request->getContent();
    – fmsthird
    Mar 19, 2019 at 0:50

1 Answer 1


Assuming $this->request is an instance of Magento\Framework\App\Request\Http, you can use the code below to get the JSON post body.

$json = $this->request->getContent();
$data = json_decode($json);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.