0

I am unable to post multi dimensional array from REST API (POST Method). posting the data in below format.

RAW DATA

{"customerData":{"name":"Mujassam", "no":"7760"}, "services":[{"product":"mobile", "id": "1"}, {"product":"day", "id":"2"}]}

Here Services is 2D Array

Interface is as below:

/** * return placed order status * @api * @param string[] $customerData * @param string[] $services * @return array */ public function createOrder($customerData, $services);

May be I am not defining 2D array properly($services)..

It gives me below error

Notice: Array to string conversion in /var/www/html/mabel/vendor/magento/framework/Reflection/TypeProcessor.php on line 496

Note: I have no problem passing the 1D array..

Hoping some body to help me..

asked Nov 2, 2016 at 12:38
1

2 Answers 2

0

You try use hashmap, not array. Magento does not support this type of object. You can use KeyValueObject[] where KeyValueObject is

class KeyValueObject
{
 function set/getKey():string
 function set/getValue():string
}

see \Magento\Framework\DataObject\KeyValueObjectInterface as example

Devtype
2,9683 gold badges26 silver badges37 bronze badges
answered Nov 2, 2016 at 13:22
1
  • Thanks for ans @KAndy .. tried method \Magento\Framework\DataObject\KeyValueObjectInterface but no luck for me.. it gives me error as below.. Fatal Error: 'Uncaught Error: Cannot instantiate interface.. help me if you can Commented Nov 3, 2016 at 5:56
-2

Use @param anyType php doc block in your interface.

answered May 11, 2018 at 12:51

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.