1

Magento 2 rest api get params returns empty array can any one tell me where I am going wrong.

i/p: in postman body => raw => json
{
    "orderids":[1,2,3]
}

(or)

{
    "orderids":"1"

}

(or)

{
    "orderids":{
        "0":"1",
        "1":"1",
        "2":"1"
    }
}

<?php
namespace Test\OrderGridSync\Model;
use Test\OrderGridSync\Api\SyncInterface;

class Sync implements SyncInterface
{   

protected $_request;

public function __construct(
    \Magento\Framework\App\Request\Http $request
) {
   $this->_request = $request;
}


/**
 * return order ids
 * @api
 * @param mix $orderids
 * @return mix 
 */
public function syncOrders() {
    print_r($this->_request->getParams());
    die('testing');
}
}

o/p:-

Array
(
)
testing

1 Answer 1

0

you have to pass data in parameters in POSTMAN like this and try to get the params in mentioned function

http://<host>/rest/V1/<endpoint>?orderids=[1,2,3]

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.