Showing results for 
Search instead for 
Did you mean: 

REST API POST of a 2D array results in error

0 Kudos

REST API POST of a 2D array results in error

Feature request from augsteyer, posted on GitHub Feb 03, 2016

I believe this is a bug where I am trying to pass a JSON object like this

         "name": "t",
         "value": "p"

Where the interface looks like this

     * @param string    $action
     * @param array[][] $settings - the type here is the problem area
     * @return string
    public function setSettings($action, $settings);

I have currently tried many variations of string[][], array[], string[], mixed[], Array[], etc, without any way of passing settings without getting an error thrown at the lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php:Smiley Tonguerocess() function.

The root cause of the problem is that in lib/internal/Magento/Framework/Webapi/ServiceInputProcessor.php::convertValue() it has no way of parsing array of arrays. If it's something like "string[][]" it will consider it a simple type and will try to match it to !settype(array(...), string), which results into an error. If it's something unknown like array[][]. It will consider it complex, and try to initialize it as a class, where it will figure out that 'array' is not a class.

A way of solving, would be to make array a simple type, however I do not know the implications of such change, hence why it's not a pull request. The change would also allow this case to be accepted whether it's array[][] or array[] or array, so most likely not a good solution.


return in_array(
                self::NORMALIZED_ARRAY_TYPE //'array' <------ 
Not applicable

Comment from jigneshkhunt, posted on GitHub Jul 20, 2016

Hello augsteyer,

I am getting same issue in magento-2.1, have you got any solution ?

Not applicable

Comment from augsteyer, posted on GitHub Jul 20, 2016

Had to abandon the mage2 API completely & use my own, at that time I did not know mage2 well enough to fix the issue. Now I could probably solve the problem, but it would require a good amount of time to test the solution. Something I do not have, hope mage2 team acknowledges the bug though.

Senior Member

hiii, still the bug not fixed