1

I created a custom API REST :

https://domain/rest/V1/action

This is a POST request, with JSON in the body.

Example :

{
  "my_test_here": [
    {
      "first_field": "value1",
      "second_field": "value2",
      "and_so_on": "value3"
    }
  ]
}

In my code, I try to get the JSON information but all my attempts are empty :

$this->request1->getParams(); // with @var \Magento\Framework\App\Request\Http $request1 $this->request2->getParams(); // with @var \Magento\Framework\Webapi\Rest\Request $request2

I try with getPost() also, but still empty...

Do you have any idea how to do ?

1 Answer 1

3

If I understand you correct you are posting json in the body

Therefore have you tried this

$this->getRequest()->getContent()

Eg

https://github.com/magento/magento2/blob/ddf42caaf25311f10b23b95a92746f99943e045e/app/code/Magento/Signifyd/Model/SignifydGateway/Response/WebhookRequest.php#L56

1
  • Use $this->request->getContent() with request = \Magento\Framework\Webapi\Rest\Request. Works perfectly, thank you !
    – Kozame
    Commented Jul 26, 2019 at 7:23

Your Answer

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

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