3

I have created many rest Api in magento2 which working perfectly... I have only problem to pass the array in custom rest api... for example I am passing the data in below format from postman.

{"vendor_data":{"name":"Mujassam", "mobile":7777}}

It gives me below error:

"message": "Class array does not exist", "code": -1,

Api interface is as below,

/**
 * return placed order status
 * @api
 * @param array[] $vendor_data
 * @return array
 */
public function createVendor($vendor_data);

EDIT: tried this but no luck

How to handle multi level array as input parameter from custom POST webservice in Magento2

Quan Le
1,7181 gold badge13 silver badges18 bronze badges
asked Oct 18, 2016 at 5:49

3 Answers 3

9

Magento 2 do not support mixed like array. You can use KayValue[] or string[] but do not array[]

see http://devdocs.magento.com/guides/v2.1/extension-dev-guide/service-contracts/service-to-web-service.html for more details

answered Oct 18, 2016 at 6:25
17

I also faced the same issue and got it fixed.Try this,

 /**
 * return placed order status
 * @api
 * @param mixed $vendor_data
 * @return array
 */
 public function createVendor($vendor_data);
answered May 24, 2017 at 8:23
0
0

Type mixed is available from version 2.2 onwards. @saravanavelu's answer won't work in versions before that.

See docs: docs

answered Nov 15, 2019 at 3:26

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.