Get wishlist of customer using Magento 2 API.

I refereed Magento Dev but, I'm not able to find wishlist for customer.

  • Wishlist module doesn't have REST API Commented Jun 11, 2018 at 15:45

2 Answers 2


Please find the Below Answer For Your Question for customer Wishlist.

To create webapi in Magento 2, we need to create a file in


in Webapi.xml Place below code.

<?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/wishlist/product/:customerid" method="GET">
        <service class="ExtensionName\ModuleName\Api\HelloInterface" method="displayWishlist"/>
            <resource ref="anonymous"/>


Then in di.xml Place below code.

<?xml version="1.0"?>
<config xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:framework:ObjectManager/etc/config.xsd">
    <preference for="ExtensionName/ModuleName\Api\HelloInterface"
                type="ExtensionName/ModuleName\Model\Hello" />

As Per the above di.xml file Create HelloInterface adn Hello


Replace the code in HelloInterface.php

namespace ExtensionName\ModuleName\Api;

interface HelloInterface
     * Returns greeting message to user
     * @api
     * @param int customer id
     * @return mixed 
    public function displayWishlist($customer_id);

Next Create Hello.php in below Path


Place below code in Hello.php

namespace ExtensionName\ModuleName\Model;
use ExtensionName\ModuleName\Api\HelloInterface;

class Hello implements HelloInterface
            private $customer_id;
            private $wishlist;
            public function __construct(
            \Magento\Wishlist\Model\Wishlist $wishlist
            ) {
                $this->wishlist = $wishlist;

            public function displayWishlist($customer_id) {
            $customer_id = 1;
            $wishlist_collection = $this->wishlist->loadByCustomerId($customer_id, true)->getItemCollection();

            $wishlist_item = array();
            foreach ($wishlist_collection as $item) {
            $productName = $item->getProduct()->getName();
            $productId = $item->getProduct()->getId();
            $WishlistItemId = $item->getWishlistItemId();
            $wishlist_item[$i]['productName'] = $productName;
            $wishlist_item[$i]['productId'] = $productId;
            $wishlist_item[$i]['WishlistItemId'] = $WishlistItemId;
            return $wishlist_item;  

For More reference please find the below screen shot.

enter image description here

  • hello i am getting fallowing error. <message>%fieldName is a required field.</message> Commented Mar 26, 2019 at 10:49
  • You have to mention resource reference as "anonymous" like <resource ref="anonymous"/> @SarveshTiwari Commented Mar 29, 2019 at 15:49
  • is itwork for post req ?
    – devmage
    Commented Jun 20, 2020 at 5:21

Just an update to answer provided by learning_coder: Replace code in Webapi.xml.

<?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/wishlist/product/:customer_id" method="GET">
        <service class="District\Customapi\Api\WishlistInterface" method="displayWishlist"/>
            <resource ref="anonymous"/>

It was an issue with parameter customer_id. Updating it would fix the issue.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.