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
Rama Chandran M
3,26515 gold badges24 silver badges38 bronze badges
asked Jun 12, 2018 at 11:46

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]
answered Jun 12, 2018 at 13:30

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

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

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.