{"id":2756,"date":"2024-12-31T20:26:31","date_gmt":"2024-12-31T20:26:31","guid":{"rendered":"https:\/\/meetanshi.com\/blog\/magento-2-api-wishlist-custom-api\/"},"modified":"2025-05-21T18:02:38","modified_gmt":"2025-05-21T12:32:38","slug":"magento-2-api-wishlist","status":"publish","type":"post","link":"https:\/\/meetanshi.com\/blog\/magento-2-api-wishlist\/","title":{"rendered":"Magento 2 API \u2013 Wishlist [Custom API]"},"content":{"rendered":"\n<p class=\"wp-block-paragraph\">Are you looking for Magento 2 API for Wishlist functionality? In the post, I\u2019ll share the Magento 2 Wishlist REST API module to add, view, move, and delete items from the Wishlist.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Product wishlist is an important feature of any online shopping store\/app.&nbsp;<a href=\"https:\/\/business.adobe.com\/products\/magento\/magento-commerce.html\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 (Adobe Commerce)<\/a>&nbsp;offers the product Wishlist functionality by default. It allows the customers to save products they wish to buy.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">The&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api\/\" target=\"_blank\" rel=\"noreferrer noopener\">Magento 2 API<\/a>&nbsp;makes it easy for developers to access its features from other apps or platforms. But, there is no native API endpoint for the Wishlist functionality in Magento 2. Therefore, you may need to develop a custom Magento 2 API to access the Wishlist features.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Well, I\u2019ve done the hard work for you! Recently, I developed a custom API module in Magento 2 to access the Wishlist features for a mobile app. In this post, I am going to share the complete module with you!<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong>This post covers<\/strong><\/em><\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Create a Magento 2 Wishlist REST API Module\n<ul class=\"wp-block-list\">\n<li>Step 1: Create and Register a Custom API Module<\/li>\n\n\n\n<li>Step 2: Define Custom Endpoint<\/li>\n\n\n\n<li>Step 3: Configure Module Dependency<\/li>\n\n\n\n<li>Step 4: Create an Interface for the Request<\/li>\n\n\n\n<li>Step 5: Create a Model<\/li>\n<\/ul>\n<\/li>\n\n\n\n<li>Magento 2 Wishlist Rest API \u2013 Complete Tutorial\n<ul class=\"wp-block-list\">\n<li>Magento 2 Wishlist API \u2013 Get Items<\/li>\n\n\n\n<li>Magento 2 Wishlist API \u2013 Add Items<\/li>\n\n\n\n<li>Magento 2 Wishlist API \u2013 Delete Items<\/li>\n\n\n\n<li>Magento 2 Wishlist API \u2013 Move to Cart<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">Let\u2019s get started with the&nbsp;<em><strong>Magento 2 Wishlist REST API<\/strong><\/em>&nbsp;module.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"create-a-magento-2-wishlist-rest-api-module\">Create a Magento 2 Wishlist REST API Module<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">In order to create a custom web API in Magento 2, we need to create a custom module. The module defines the route for the Magento 2 API endpoint, along with its functions. Below is a step-wise method to create the Magento 2 REST API module for Wishlist.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><em><strong>Note:&nbsp;<\/strong>Replace \u2018Meetanshi\u2019 &amp; CustomRestApi in the below provided codes with your vendor name and module name. The directory of each of the files will also change accordingly.<\/em><\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-1-create-and-register-a-custom-api-module\">Step 1: Create and Register a Custom API Module<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">First, you need to register the custom API module for Wishlist in Magento 2. For that, create&nbsp;<strong>module.xml<\/strong>&nbsp;and&nbsp;<strong>registration.php<\/strong>&nbsp;files at the following directory:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><em>app\/code\/Meetanshi\/CustomRestApi\/etc\/module.xml<\/em><\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\u201d1.0\u2033?>\n&lt;config xmlns:xsi=\u201dhttp:\/\/www.w3.org\/2001\/XMLSchema-instance\u201d xsi:noNamespaceSchemaLocation=\u201durn:magento:framework:Module\/etc\/module.xsd\u201d>\n&lt;module name=\u201dMeetanshi_CustomRestApi\u201d setup_version=\u201d0.0.1\u2033\/>\n&lt;\/config><\/pre>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em><strong>app\/code\/Meetanshi\/CustomRestApi\/registration.php<\/strong><\/em><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\\Magento\\Framework\\Component\\ComponentRegistrar::register(\n\\Magento\\Framework\\Component\\ComponentRegistrar::MODULE,\n\u2018Meetanshi_CustomRestApi\u2019,\n__DIR__\n);<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-2-define-custom-endpoint\">Step 2: Define Custom Endpoint<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Now, define the endpoint for the custom REST API in Magento 2 for the Wishlist. To do that, you need to create a&nbsp;<em><strong>webapi.xml&nbsp;<\/strong><\/em>file as presented below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em><strong><em><strong>\\app\\code\\Meetanshi\\CustomRestApi\\etc\\webapi.xml<\/strong><\/em><\/strong><\/em><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;routes xmlns:xsi=\"http:\/\/www.w3.org\/2001\/XMLSchema-instance\" xsi:noNamespaceSchemaLocation=\"urn:magento:module:Magento_Webapi:etc\/webapi.xsd\">\n    &lt;route url=\"\/V1\/wishlist\" method=\"POST\">\n        &lt;service class=\"Meetanshi\\CustomRestApi\\Api\\WishlistManagementInterface\" method=\"add\"\/>\n        &lt;resources>\n            &lt;resource ref=\"self\"\/>\n        &lt;\/resources>\n        &lt;data>\n            &lt;parameter name=\"customerId\" force=\"true\">%customer_id%&lt;\/parameter>\n        &lt;\/data>\n    &lt;\/route>\n\n    &lt;route url=\"\/V1\/wishlist\" method=\"GET\">\n        &lt;service class=\"Meetanshi\\CustomRestApi\\Api\\WishlistManagementInterface\" method=\"get\"\/>\n        &lt;resources>\n            &lt;resource ref=\"self\"\/>\n        &lt;\/resources>\n        &lt;data>\n            &lt;parameter name=\"customerId\" force=\"true\">%customer_id%&lt;\/parameter>\n        &lt;\/data>\n    &lt;\/route>\n\n    &lt;route url=\"\/V1\/wishlist\/:itemId\" method=\"DELETE\">\n        &lt;service class=\"Meetanshi\\CustomRestApi\\Api\\WishlistManagementInterface\" method=\"delete\"\/>\n        &lt;resources>\n            &lt;resource ref=\"self\"\/>\n        &lt;\/resources>\n        &lt;data>\n            &lt;parameter name=\"customerId\" force=\"true\">%customer_id%&lt;\/parameter>\n        &lt;\/data>\n    &lt;\/route>\n\n    &lt;route url=\"\/V1\/wishlist\/move\" method=\"POST\">\n        &lt;service class=\"Meetanshi\\CustomRestApi\\Api\\WishlistManagementInterface\" method=\"move\"\/>\n        &lt;resources>\n            &lt;resource ref=\"self\"\/>\n        &lt;\/resources>\n        &lt;data>\n            &lt;parameter name=\"customerId\" force=\"true\">%customer_id%&lt;\/parameter>\n        &lt;\/data>\n    &lt;\/route>\n&lt;\/routes><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-3-configure-module-dependency\">Step 3: Configure Module Dependency<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create a&nbsp;<em><strong>di.xml<\/strong><\/em>&nbsp;file for the Magento 2 module as shown below:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em><strong><em><strong>\\app\\code\\Meetanshi\\CustomRestApi\\etc\\di.xml<\/strong><\/em><\/strong><\/em><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?xml version=\u201d1.0\u2033?>\n&lt;config xmlns:xsi=\u201dhttp:\/\/www.w3.org\/2001\/XMLSchema-instance\u201d xsi:noNamespaceSchemaLocation=\u201durn:magento:framework:ObjectManager\/etc\/config.xsd\u201d>\n&lt;preference for=\u201dMeetanshi\\CustomRestApi\\Api\\WishlistManagementInterface\u201d type=\u201dMeetanshi\\CustomRestApi\\Model\\WishlistManagement\u201d\/>\n&lt;\/config><\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-4-create-an-interface-for-the-request\">Step 4: Create an Interface for the Request<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Create an interface for Magento 2 Wishlist API. You can do this by adding the following file:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong><strong><strong><em>\\app\\code\\Meetanshi\\CustomRestApi\\Model\\WishlistManagementbb.php<\/em><\/strong><\/strong><\/strong><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Meetanshi\\CustomRestApi\\Api;\n\ninterface WishlistManagementInterface\n{\n    \/**\n     * Get wishlist items for a customer.\n     *\n     * @param int $customerId\n     * @return \\Meetanshi\\CustomRestApi\\Api\\Data\\WishlistInterface\n     *\/\n    public function get(int $customerId);\n\n    \/**\n     * Add an item to the wishlist.\n     *\n     * @param int $customerId\n     * @param \\Meetanshi\\CustomRestApi\\Api\\Data\\RequestInterface $item\n     * @return \\Meetanshi\\CustomRestApi\\Api\\Data\\WishlistInterface\n     *\/\n    public function add(int $customerId, $item);\n\n    \/**\n     * Move an item from wishlist to cart.\n     *\n     * @param int $customerId\n     * @param int $quoteId\n     * @param int $itemId\n     * @return \\Meetanshi\\CustomRestApi\\Api\\Data\\WishlistInterface\n     *\/\n    public function move(int $customerId, int $quoteId, int $itemId);\n\n    \/**\n     * Delete an item from the wishlist.\n     *\n     * @param int $customerId\n     * @param int $itemId\n     * @return bool\n     *\/\n    public function delete(int $customerId, int $itemId): bool;\n}\n<\/pre>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"step-5-create-a-model\">Step 5: Create a Model<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Lastly, create a model for the Magento 2 Wishlist API.<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><em><strong>\\app\\code\\Meetanshi\\CustomRestApi\\Model\\WishlistManagementbb.php<\/strong><\/em><\/li>\n<\/ul>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">&lt;?php\n\nnamespace Meetanshi\\CustomRestApi\\Model;\n\nuse Magento\\Catalog\\Api\\ProductRepositoryInterface;\nuse Magento\\Framework\\DataObject;\nuse Magento\\Framework\\Event\\ManagerInterface;\nuse Magento\\Framework\\Exception\\LocalizedException;\nuse Magento\\Framework\\Exception\\NoSuchEntityException;\nuse Magento\\Wishlist\\Model\\WishlistFactory;\nuse Meetanshi\\CustomRestApi\\Api\\WishlistManagementInterface;\n\nclass WishlistManagement implements WishlistManagementInterface\n{\n    \/**\n     * @var WishlistFactory\n     *\/\n    private $wishlistFactory;\n\n    \/**\n     * @var ProductRepositoryInterface\n     *\/\n    private $productRepository;\n\n    \/**\n     * @var ManagerInterface\n     *\/\n    private $eventManager;\n\n    \/**\n     * @var \\Magento\\Catalog\\Helper\\Product\\Configuration\n     *\/\n    private $productHelper;\n\n    \/**\n     * WishlistManagement constructor.\n     *\n     * @param WishlistFactory $wishlistFactory\n     * @param ProductRepositoryInterface $productRepository\n     * @param ManagerInterface $eventManager\n     * @param \\Magento\\Catalog\\Helper\\Product\\Configuration $productHelper\n     *\/\n    public function __construct(\n        WishlistFactory $wishlistFactory,\n        ProductRepositoryInterface $productRepository,\n        ManagerInterface $eventManager,\n        \\Magento\\Catalog\\Helper\\Product\\Configuration $productHelper\n    ) {\n        $this->wishlistFactory = $wishlistFactory;\n        $this->productRepository = $productRepository;\n        $this->eventManager = $eventManager;\n        $this->productHelper = $productHelper;\n    }\n\n    \/**\n     * Get wishlist for a customer\n     *\n     * @param int $customerId\n     * @return \\Magento\\Wishlist\\Model\\Wishlist|\\Meetanshi\\CustomRestApi\\Api\\Data\\WishlistInterface\n     * @throws NoSuchEntityException\n     *\/\n    public function get(int $customerId)\n    {\n        $wishlist = $this->wishlistFactory->create()->loadByCustomerId($customerId);\n\n        if (!$wishlist->getId()) {\n            $wishlist['items'] = [];\n            $wishlist['error'] = ['Customer does not yet have a wishlist'];\n            return $wishlist;\n        }\n\n        $objectManager = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n        $helper = $objectManager->get('Meetanshi\\CustomRestApi\\Helper\\Data');\n        $helperPool = $objectManager->get('Magento\\Catalog\\Helper\\Product\\ConfigurationPool');\n\n        $storeUrl = $helper->getStoreUrl();\n        $mediaUrl = $helper->isRemovePub() \n            ? $storeUrl . '\/media\/catalog\/product\/' \n            : $storeUrl . '\/pub\/media\/catalog\/product\/';\n\n        $product_img = [];\n        $productItems = [];\n\n        foreach ($wishlist->getItemCollection()->getItems() as $item) {\n            $productId = $item->getProductId();\n\n            try {\n                $product = $this->productRepository->getById($productId);\n\n                $helperInstance = match ($product->getTypeId()) {\n                    \"bundle\" => \\Magento\\Bundle\\Helper\\Catalog\\Product\\Configuration::class,\n                    \"downloadable\" => \\Magento\\Downloadable\\Helper\\Catalog\\Product\\Configuration::class,\n                    default => \\Magento\\Catalog\\Helper\\Product\\Configuration::class\n                };\n\n                $productItems[] = [\n                    \"wishlist_item_id\" => $item->getId(),\n                    \"product_id\" => $productId,\n                    \"name\" => $product->getData('name'),\n                    \"price\" => number_format($item->getProduct()->getFinalPrice() ?? 0, 2, '.', ''),\n                    \"sku\" => $product->getSku(),\n                    \"qty\" => $item->getQty(),\n                    \"special_price\" => number_format($item->getProduct()->getSpecialPrice() ?? 0, 2, '.', ''),\n                    \"image\" => $mediaUrl . $product->getData('image'),\n                    \"thumbnail\" => $mediaUrl . $product->getData('thumbnail'),\n                    \"small_image\" => $mediaUrl . $product->getData('small_image'),\n                    \"product_type\" => $product->getTypeId(),\n                    \"product_options\" => $this->getConfiguredOptions($item, $helperPool, $helperInstance)\n                ];\n            } catch (\\Exception $e) {\n                \/\/ Silently ignore any errors for individual products\n            }\n        }\n\n        $wishlist['items'] = array_merge($productItems, $product_img);\n        return $wishlist;\n    }\n\n    \/**\n     * Get configured options for a wishlist item\n     *\n     * @param mixed $item\n     * @param mixed $helperPool\n     * @param mixed $mainHelper\n     * @return mixed\n     *\/\n    public function getConfiguredOptions($item, $helperPool, $mainHelper)\n    {\n        $helper = $helperPool->get($mainHelper);\n        $options = $helper->getOptions($item);\n\n        foreach ($options as $index => $option) {\n            if (is_array($option) &amp;&amp; array_key_exists('value', $option)) {\n                if (!(array_key_exists('has_html', $option) &amp;&amp; $option['has_html'] === true)) {\n                    if (is_array($option['value'])) {\n                        foreach ($option['value'] as $key => $value) {\n                            $option['value'][$key] = $value;\n                        }\n                    }\n                }\n                $options[$index]['value'] = $option['value'];\n            }\n        }\n\n        return $options;\n    }\n\n    \/**\n     * Add item to wishlist\n     *\n     * @param int $customerId\n     * @param \\Meetanshi\\CustomRestApi\\Api\\Data\\RequestInterface $item\n     * @return \\Magento\\Wishlist\\Model\\Wishlist|\\Meetanshi\\CustomRestApi\\Api\\Data\\WishlistInterface\n     * @throws LocalizedException\n     * @throws NoSuchEntityException\n     *\/\n    public function add(int $customerId, $item)\n    {\n        $wishlist = $this->wishlistFactory->create()->loadByCustomerId($customerId, true);\n        $product = $this->productRepository->get($item->getProduct());\n\n        if (!$product->isVisibleInCatalog()) {\n            throw new LocalizedException(__(\"Sorry, this item can't be added to wishlists\"), null, 1);\n        }\n\n        $buyRequest = new DataObject();\n        $customAttributes = $item->getCustomAttributes();\n\n        if ($customAttributes) {\n            $superAttributes = [];\n            $bundleOptionQtys = [];\n            $bundleOptions = [];\n\n            foreach ($customAttributes as $customAttribute) {\n                if (strpos($customAttribute->getAttributeCode(), 'super_attribute_') === 0) {\n                    $superAttributeId = str_replace('super_attribute_', '', $customAttribute->getAttributeCode());\n                    $superAttributes[$superAttributeId] = $customAttribute->getValue();\n                    continue;\n                }\n\n                if (strpos($customAttribute->getAttributeCode(), 'bundle_option_qty_') === 0) {\n                    $bundleOptionQty = str_replace('bundle_option_qty_', '', $customAttribute->getAttributeCode());\n                    $bundleOptionQtys[$bundleOptionQty] = $customAttribute->getValue();\n                    continue;\n                }\n\n                if (strpos($customAttribute->getAttributeCode(), 'bundle_option_') === 0) {\n                    $bundleOption = str_replace('bundle_option_', '', $customAttribute->getAttributeCode());\n                    $bundleOption = explode('_', $bundleOption);\n\n                    if (count($bundleOption) === 1) {\n                        $bundleOptions[$bundleOption[0]] = $customAttribute->getValue();\n                    } elseif (count($bundleOption) === 2) {\n                        $bundleOptions[$bundleOption[0]][$bundleOption[1]] = $customAttribute->getValue();\n                    }\n                    continue;\n                }\n            }\n\n            if ($superAttributes) {\n                $buyRequest->setData('super_attributes', $superAttributes);\n            }\n\n            if ($bundleOptionQtys) {\n                $buyRequest->setData('bundle_option_qty', $bundleOptionQtys);\n            }\n\n            if ($bundleOptions) {\n                $buyRequest->setData('bundle_option', $bundleOptions);\n            }\n        }\n\n        $result = $wishlist->addNewItem($product, $buyRequest);\n\n        if (is_string($result)) {\n            throw new LocalizedException(__($result), null, 2);\n        }\n\n        if ($wishlist->isObjectNew()) {\n            $wishlist->save();\n        }\n\n        $this->eventManager->dispatch(\n            'wishlist_add_product',\n            ['wishlist' => $wishlist, 'product' => $product, 'item' => $result]\n        );\n\n        $wishlist['items'] = $wishlist->getItemCollection()->getItems();\n        return $wishlist;\n    }\n\n    \/**\n     * Move item from quote to wishlist\n     *\n     * @param int $customerId\n     * @param int $quoteId\n     * @param int $itemId\n     * @return \\Meetanshi\\CustomRestApi\\Api\\Data\\WishlistInterface\n     * @throws LocalizedException\n     *\/\n    public function move(int $customerId, int $quoteId, int $itemId)\n    {\n        $wishlist = $this->wishlistFactory->create()->loadByCustomerId($customerId, true);\n        $buyRequest = new DataObject();\n        $om = \\Magento\\Framework\\App\\ObjectManager::getInstance();\n        $quote = $om->get('Magento\\Quote\\Model\\Quote');\n        $quoteItems = $quote->load($quoteId)->getAllVisibleItems();\n        $status = false;\n\n        try {\n            foreach ($quoteItems as $quoteItem) {\n                $_productId = $quoteItem->getProductId();\n                $product = $this->productRepository->getById($_productId);\n\n                if (!$product->isVisibleInCatalog()) {\n                    throw new LocalizedException(__(\"Sorry, this item can't be added to wishlists\"), null, 1);\n                }\n\n                if ($quoteItem->getId() == $itemId) {\n                    $buyRequest = $quoteItem->getBuyRequest();\n                    $status = true;\n                    break;\n                }\n            }\n\n            $options = $buyRequest->getOptions();\n            if ($buyRequest->getOptions()) {\n                foreach ($buyRequest->getOptions() as $key => $option) {\n                    if (is_array($option)) {\n                        if (isset($option['date_internal'])) {\n                            unset($options[$key]);\n                            $options[$key] = $option['date_internal'];\n                        }\n                    }\n                }\n                $buyRequest->setData('options', $options);\n            }\n\n            if ($status) {\n                $result = $wishlist->addNewItem($product, $buyRequest);\n\n                if (is_string($result)) {\n                    throw new LocalizedException(__($result), null, 2);\n                }\n\n                if ($wishlist->isObjectNew()) {\n                    $wishlist->save();\n                }\n\n                $this->eventManager->dispatch(\n                    'wishlist_add_product',\n                    ['wishlist' => $wishlist, 'product' => $product, 'item' => $result]\n                );\n\n                $wishlist['items'] = $wishlist->getItemCollection()->getItems();\n            }\n        } catch (\\Exception $e) {\n            throw new LocalizedException(__($e->getMessage()), null, 1);\n        }\n\n        return $wishlist;\n    }\n\n    \/**\n     * Delete item from wishlist\n     *\n     * @param int $customerId\n     * @param int $itemId\n     * @return bool\n     * @throws \\Exception\n     *\/\n    public function delete(int $customerId, int $itemId): bool\n    {\n        $wishlist = $this->wishlistFactory->create()->loadByCustomerId($customerId);\n        $item = $wishlist->getItem($itemId);\n\n        if (!$item) {\n            throw new NoSuchEntityException(__('No item with ID %1', $itemId), null, 1);\n        }\n\n        $item->delete();\n        return true;\n    }\n}<\/pre>\n\n\n\n<h2 class=\"wp-block-heading\" id=\"magento-2-wishlist-rest-api-complete-tutorial\">Magento 2 Wishlist Rest API \u2013 Complete Tutorial<\/h2>\n\n\n\n<p class=\"wp-block-paragraph\">The above Magento 2 Wishlist Rest APIs module allows you to perform the following actions through API:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li>Get Items<\/li>\n\n\n\n<li>Add Items<\/li>\n\n\n\n<li>Delete Items<\/li>\n\n\n\n<li>Move Items to Cart<\/li>\n<\/ul>\n\n\n\n<p class=\"wp-block-paragraph\">The Magento 2 Wishlist API is a customer API and requires the&nbsp;<a href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-get-customer-token\/\" target=\"_blank\" rel=\"noreferrer noopener\">customer token for authorization<\/a>. Therefore, you need to pass the customer token in the header of each of the requests for authorization.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"magento-2-wishlist-api-get-items\">Magento 2 Wishlist API \u2013 Get Items<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Here\u2019s how you can use this API to get wishlist items in Magento 2.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Method:&nbsp;<\/strong>GET<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Endpoint URL:&nbsp;<\/strong><code>&lt;store_url&gt;\/rest\/V1\/wishlist<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Authorization:&nbsp;<\/strong>Bearer Token &lt;customer_token&gt;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/04\/Magento-2-API-Wishlist-Get-Items.png\" alt=\"Magento 2 Wishlist API - Get Items\" class=\"wp-image-31170\"\/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"magento-2-wishlist-api-add-items\">Magento 2 Wishlist API \u2013 Add Items<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\">Use this API reference to Magento 2 add to Wishlist programmatically.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Method:&nbsp;<\/strong>POST<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Endpoint URL:&nbsp;<\/strong><code>&lt;store_url&gt;\/rest\/V1\/wishlist<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Authorization:&nbsp;<\/strong>Bearer Token &lt;customer_token&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Body:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n    \"item\": {\n        \"product\":\"Gift Card\",\n        \"qty\":1 \n    }\n}<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/04\/Add-item-to-wishlist-using-Magento-2-API.png\" alt=\"Magento 2 Wishlist API to Add Item to Wishlist\" class=\"wp-image-31171\"\/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"magento-2-wishlist-api-delete-items\">Magento 2 Wishlist API \u2013 Delete Items<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Method:&nbsp;<\/strong>DELETE<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Endpoint:&nbsp;<\/strong><code>&lt;store_url&gt;\/rest\/V1\/wishlist\/&lt;wishlist_id&gt;<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Authorization:&nbsp;<\/strong>Bearer Token &lt;customer_token&gt;<\/p>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/04\/Delete-Wishlist-using-Magento-2-API.png\" alt=\"Delete Wishlist Using Magento 2 API\" class=\"wp-image-31173\"\/><\/figure>\n<\/div>\n\n\n<h3 class=\"wp-block-heading\" id=\"magento-2-wishlist-api-move-to-cart\">Magento 2 Wishlist API \u2013 Move to Cart<\/h3>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Method:&nbsp;<\/strong>POST<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Endpoint:&nbsp;<\/strong><code>&lt;store_url&gt;\/rest\/v1\/wishlist\/move\/<\/code><\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Authorization:&nbsp;<\/strong>Bearer Token &lt;customer_token&gt;<\/p>\n\n\n\n<p class=\"wp-block-paragraph\"><strong>Body:<\/strong><\/p>\n\n\n\n<pre class=\"EnlighterJSRAW\" data-enlighter-language=\"generic\" data-enlighter-theme=\"\" data-enlighter-highlight=\"\" data-enlighter-linenumbers=\"\" data-enlighter-lineoffset=\"\" data-enlighter-title=\"\" data-enlighter-group=\"\">{\n\t\"quoteId\":3332,\n        \"itemId\":7771\n\t}\n}<\/pre>\n\n\n<div class=\"wp-block-image\">\n<figure class=\"aligncenter size-full\"><img decoding=\"async\" src=\"https:\/\/meetanshi.com\/blog\/wp-content\/uploads\/2023\/04\/Move-wishlist-to-cart-using-Magento-2-API.png\" alt=\"Move wishlist to cart using Magento 2 API\" class=\"wp-image-31172\"\/><\/figure>\n<\/div>\n\n\n<p class=\"wp-block-paragraph\">That\u2019s everything about the Magento 2 Wishlist API. Follow the steps provided above to create the custom Magento 2 Wishlist REST API and access the Wishlist features through API.<\/p>\n\n\n\n<p class=\"wp-block-paragraph\">Thank You!  <\/p>\n\n\n\n<div class=\"wp-block-buttons is-content-justification-center is-layout-flex wp-container-core-buttons-is-layout-fe48e5de wp-block-buttons-is-layout-flex\">\n<div class=\"wp-block-button btn-orange\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-create-coupon-code\/\">Magento 2 API \u2013 Create Coupon Code<\/a><\/div>\n\n\n\n<div class=\"wp-block-button btn-orange\"><a class=\"wp-block-button__link wp-element-button\" href=\"https:\/\/meetanshi.com\/blog\/magento-2-api-create-credit-memo\/\">Magento 2 API \u2013 Create Credit Memo<\/a><\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>Are you looking for Magento 2 API for Wishlist functionality? In the post, I\u2019ll share the Magento 2 Wishlist REST API module to add, view,&#8230;<\/p>\n","protected":false},"author":38,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[34],"tags":[],"class_list":["post-2756","post","type-post","status-publish","format-standard","hentry","category-magento"],"acf":[],"_links":{"self":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2756","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/users\/38"}],"replies":[{"embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/comments?post=2756"}],"version-history":[{"count":5,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2756\/revisions"}],"predecessor-version":[{"id":14039,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/posts\/2756\/revisions\/14039"}],"wp:attachment":[{"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/media?parent=2756"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/categories?post=2756"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/meetanshi.com\/blog\/wp-json\/wp\/v2\/tags?post=2756"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}