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?

Sukumar Gorai
11k4 gold badges20 silver badges47 bronze badges
asked Oct 8, 2018 at 10:52

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

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

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.