cancel
Showing results for 
Search instead for 
Did you mean: 

how to get raw body json data in rest api

how to get raw body json data in rest api

Hello

Can anyone please help me how do I get raw body json data in rest APi in magento 2

here is the code

namespace Apidata\Ondc\Model;
use Magento\Contact\Model\MailInterface;
use Magento\Framework\Exception\LocalizedException;
use Magento\Framework\DataObject;


class PostManagement {

private $mail;

protected $dataObjectFactory;

/**
* {@inheritdoc}
*/
public function __construct(
MailInterface $mail,
\Magento\Framework\DataObjectFactory $dataObjectFactory,
\Magento\Framework\Webapi\Rest\Request $request
) {

$this->mail = $mail;
$this->dataObjectFactory = $dataObjectFactory;
$this->request = $request;
}
public function getPost()
{
$return = [];
$jayParsedAry =[];
$body = $this->request->getBodyParams();


var_dump($body);

 

return json_encode($body);
}

}

 

Screenshot from 2023-08-09 19-38-17.png

1 REPLY 1

Re: how to get raw body json data in rest api

use the below code

use Magento\Framework\App\PlainTextRequestInterface;
$this->plainTextRequest->getContent();