1

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?

1

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 value – Ramkishan Suthar Jun 7 at 5:05

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.