Magento 2.2 REST API Error with ‘@param string[] $types’ – Fix

jsonmagento2.2parameterrest api

Using magento 2.2. I create rest api for edit address which need pass param in 'array of string' but i get an error:

Doc: Magento Configure services as web APIs

Used array of string for pass param

"street": ["new, wat phnom, phnom penh"]

Message

"message": "Error occurred during \"street\" processing. Invalid type for value: \"array\". Expected Type: \"string\".",

My JSON

{
"address":{
"addressId":85,
"street": ["new, wat phnom, phnom penh"],
"latitude":"11.33333664",
"longitude":"104.99778855"
}
}

Interface

<?php
namespace Iota\EShopping\Model\Address;

class Address
 {
private $addressId;
private $street;


/**
 * addressId
 * @return int
 */
public function getAddressId(){
    return $this->addressId;
}

/**
 * addressId
 * @param int $addressId
 * @return Address
 */
public function setAddressId($addressId){
    $this->addressId = $addressId;
    return $this;
}


/**
 * street
 * @return string
 */
public function getStreet(){
    return $this->street;
}

/**
 * street
 * @param string[] $street
 * @return Address
 */
public function setStreet($street){
    $this->street = $street;
    return $this;
}
}

Best Answer

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 
Related Topic