1

I have below JSON Data for rest API {"region_id":"475","city":"city","item":[{"qty":"1","weight":"","price":"10.0000","sku":"test"}]} and i wann to create api class

I do like this

/**
 * @api
 * @param string $city
 * @param string $region_id
 * @param array $item
 * @return [].
 */
    public function estimate($city,$region_id,$item);

But return Class array does not exist also I use string [] and I get the same error. How I can pass an array as parameters?

1 Answer 1

3

pass return type @return array

Update your code with this solution :

/**
 * @api
 * @param string $city
 * @param string $region_id
 * @param array $item
 * @return array
 */
    public function estimate($city,$region_id,$item);

Valid scalar types include: mixed (or anyType), bool (or boolean), str (or string), integer (or int), float, and double

Any parameters or return values of type array can be denoted by following any of the previous types by an empty set of square brackets []

@return array|int|string|bool|float Scalar or array of scalars 

Reference

https://devdocs.magento.com/guides/v2.2/extension-dev-guide/service-contracts/service-to-web-service.html

1
  • you're welcome :) Commented Oct 8, 2018 at 11:53

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.