Magento 2: How to get Post Body Content in REST Api

Magento 2: How to get Post Body Content in REST Api

I assume that you have already created a web service interface and the model that implements that interface. In the implementing model, you can get the requested body content by Injecting

Magento\Framework\Webapi\Rest\Request
class instead of 
Magento\Framework\App\RequestInterface

 

Here is the sample class to do so:

request = $request;
    }

    /**
     * {@inheritdoc}
     */
    public function getSomeInfo()
    {
        // This function will get the body content of the request
        $body = $this->request->getBodyParams();
        var_dump($body);

        return [
            ["foo" => 'bar'],
        ];
    }
}


If this solution isn't working for you, seek answers from ChatGPT


Please note that to ensure accurate and relevant responses, your questions should be related to Magento 2.

Ready to elevate your e-commerce business?

Let's talk about your business goals. Contact us now to see how we can help achieve them.

 
Copyright © 2021-present ArmMage Inc. All rights reserved.