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..
-
Answer has been posted here magento.stackexchange.com/questions/326796/…Ekta Puri– Ekta Puri2023年05月15日 02:59:39 +00:00Commented May 15, 2023 at 2:59
2 Answers 2
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
-
Thanks for ans @KAndy .. tried method
\Magento\Framework\DataObject\KeyValueObjectInterfacebut no luck for me.. it gives me error as below.. Fatal Error: 'Uncaught Error: Cannot instantiate interface.. help me if you canMohammad Mujassam– Mohammad Mujassam2016年11月03日 05:56:46 +00:00Commented Nov 3, 2016 at 5:56
Use @param anyType php doc block in your interface.
Explore related questions
See similar questions with these tags.