Magento 2 custom rest api,I can not get an array in modalrepository,
How can i pass an array as parameter ?
Webapi.xml
<route method="POST" url="/V1/topmarkens/productlists">
<service class="MeridianTopMarkenApiTopMarkenRepositoryInterface"
method="productFilterByBrand"/>
<resources>
<resource ref="anonymous"/>
</resources>
<data>
<parameter name="types" force="true">%types%</parameter>
</data>
</route>
TopMarkenRepositoryInterface.php
/**
* return placed order status
* @param string[] $types
* @return MeridianTopMarkenApiDataTopMarkenInterface
*/
public function productFilterByBrand($types);
TopMarkenRepository.php
public function productFilterByBrand($types){
$vendor_data = json_decode($types);
echo "<pre>"; print_r($vendor_data); die;
return $vendor_data;
}
2
Answers
Directly sending an array as a parameter is not a good way of doing a POST request. I suggest you to send a json object in which u can have array as an first element of your object.
I have this json:
and this is my interface:
Using
string[]
orarray
ormixed[]
didn’t work out for me. Onlymixed