I made an API which returns wishlist of a user using customer_token as authentication, obtained via this API:
rest/V1/integration/customer/token
My webapi.xml looks something like:
<?xml version="1.0"?>
<routes xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Webapi:etc/webapi.xsd">
<route url="/V1/fetch_wishlist/" method="GET">
<service class="Vendor\WishlistApi\Api\WishlistInterface" method="setData"/>
<resources>
<resource ref="self" />
</resources>
<data>
<parameter name="customerId" force="true">%customer_id%</parameter>
</data>
</route>
</routes>
But I am getting an error as:
{
"message": "Invalid type for value: \"string\". Expected Type: \"string[]\".",
"trace": null
}
Rest of my code is correct, I used this API with anonymous resource in webapi.xml and it works fine if i send the payload as:
{"customerId": [3500]}
However I get the same exact error if I put the payload as:
{"customerId": 3500}
Any suggestions?
2 Answers 2
Fixed it by including these comments over the function in the interface:
/**
* GET for wishlist api
* @param string $customerId
* @return string
*/
-
param string $customerId this should be param int $customerId. When you pass token in header it converts to customer id which is type of integer valueRamkishan Suthar– Ramkishan Suthar2019年06月07日 05:05:48 +00:00Commented Jun 7, 2019 at 5:05
I wish complement previous response, additionally, change type in @param, you need compile the project, so its works
good luck !