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);
}
}
use the below code
use Magento\Framework\App\PlainTextRequestInterface;
$this->plainTextRequest->getContent();