Need REST api for “Add to Wishlist” in Magento 2Magento 2 : Wish list of customer Using APIHow to create Rest API for the Magento 1.9 hosted in local machineMagento 2 REST API paypal paymentMagento add product to wishlist in REST ApiMagento - Create order using REST APImagento2 add to cart rest apiHow to create and use REST API for mobile app?Place Order Magento 2.1 REST API as a guest for Android appMagento 2: Can I set a completely custom API endpoint without /rest/V1/?How get wishlist in Magento 2 Rest API?

India just shot down a satellite from the ground. At what altitude range is the resulting debris field?

How to pronounce the slash sign

How do I go from 300 unfinished/half written blog posts, to published posts?

How does Loki do this?

Method to test if a number is a perfect power?

How do I rename a Linux host without needing to reboot for the rename to take effect?

How to be diplomatic in refusing to write code that breaches the privacy of our users

Where does the Z80 processor start executing from?

Was a professor correct to chastise me for writing "Prof. X" rather than "Professor X"?

Anatomically Correct Strange Women In Ponds Distributing Swords

Pole-zeros of a real-valued causal FIR system

Crossing the line between justified force and brutality

Avoiding estate tax by giving multiple gifts

Arithmetic mean geometric mean inequality unclear

Two monoidal structures and copowering

What is paid subscription needed for in Mortal Kombat 11?

Energy of the particles in the particle accelerator

Flow chart document symbol

How does it work when somebody invests in my business?

Replace character with another only if repeated and not part of a word

Sequence of Tenses: Translating the subjunctive

What can we do to stop prior company from asking us questions?

System.debug(JSON.Serialize(o)) Not longer shows full string

Hostile work environment after whistle-blowing on coworker and our boss. What do I do?



Need REST api for “Add to Wishlist” in Magento 2


Magento 2 : Wish list of customer Using APIHow to create Rest API for the Magento 1.9 hosted in local machineMagento 2 REST API paypal paymentMagento add product to wishlist in REST ApiMagento - Create order using REST APImagento2 add to cart rest apiHow to create and use REST API for mobile app?Place Order Magento 2.1 REST API as a guest for Android appMagento 2: Can I set a completely custom API endpoint without /rest/V1/?How get wishlist in Magento 2 Rest API?













5















I want REST api for "Add to Wishlist" in Magento 2, and also need to know in which folder to place and the endpoint










share|improve this question






















  • Refer following for creating Whilist API. magento.stackexchange.com/questions/229452/…

    – Niranjan Gondaliya
    Oct 5 '18 at 4:24















5















I want REST api for "Add to Wishlist" in Magento 2, and also need to know in which folder to place and the endpoint










share|improve this question






















  • Refer following for creating Whilist API. magento.stackexchange.com/questions/229452/…

    – Niranjan Gondaliya
    Oct 5 '18 at 4:24













5












5








5


2






I want REST api for "Add to Wishlist" in Magento 2, and also need to know in which folder to place and the endpoint










share|improve this question














I want REST api for "Add to Wishlist" in Magento 2, and also need to know in which folder to place and the endpoint







magento2 rest wishlist android






share|improve this question













share|improve this question











share|improve this question




share|improve this question










asked Apr 6 '16 at 6:36









Sujay NaikSujay Naik

262




262












  • Refer following for creating Whilist API. magento.stackexchange.com/questions/229452/…

    – Niranjan Gondaliya
    Oct 5 '18 at 4:24

















  • Refer following for creating Whilist API. magento.stackexchange.com/questions/229452/…

    – Niranjan Gondaliya
    Oct 5 '18 at 4:24
















Refer following for creating Whilist API. magento.stackexchange.com/questions/229452/…

– Niranjan Gondaliya
Oct 5 '18 at 4:24





Refer following for creating Whilist API. magento.stackexchange.com/questions/229452/…

– Niranjan Gondaliya
Oct 5 '18 at 4:24










4 Answers
4






active

oldest

votes


















2















  1. Create a module Test_Mobileshop



Please follow the below steps with the file paths




2.app/code/Test/Mobileshop/etc/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/items" method="GET">
<service class="TestMobileshopApiWishlistManagementInterface" method="getWishlistForCustomer"/>
<resources>
<resource ref="anonymous" />
</resources>
<data>
<parameter name="customerId" force="true">%customer_id%</parameter>
</data>
</route>
<route url="/V1/wishlist/add/:productId" method="POST">
<service class="TestMobileshopApiWishlistManagementInterface" method="addWishlistForCustomer"/>
<resources>
<resource ref="anonymous" />
</resources>
<data>
<parameter name="customerId" force="true">%customer_id%</parameter>
</data>
</route>
</routes>



  1. app/code/Test/Mobileshop/etc/di.xml



<?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="TestMobileshopApiWishlistManagementInterface" type="TestMobileshopModelWishlistManagement" />
</config>



  1. app/code/Test/Mobileshop/Api/WishlistManagementInterface.php



<?php
/**
* A Magento 2 module named Test/Mobileshop
*
*/
namespace TestMobileshopApi;

/**
* Interface WishlistManagementInterface
* @api
*/
interface WishlistManagementInterface


/**
* Return Wishlist items.
*
* @param int $customerId
* @return array
*/
public function getWishlistForCustomer($customerId);

/**
* Return Added wishlist item.
*
* @param int $customerId
* @param int $productId
* @return array
*
*/
public function addWishlistForCustomer($customerId,$productId);





  1. app/code/Test/Mobileshop/Model/WishlistManagement.php



<?php
/**
* A Magento 2 module named Test/Mobileshop
*
*/
namespace TestMobileshopModel;

use TestMobileshopApiWishlistManagementInterface;
use MagentoWishlistControllerWishlistProvider;
use MagentoWishlistModelResourceModelItemCollectionFactory;
use MagentoWishlistModelWishlistFactory;
use MagentoCatalogApiProductRepositoryInterface;
use MagentoFrameworkExceptionLocalizedException;
use MagentoCatalogHelperImageFactory as ProductImageHelper;
use MagentoStoreModelAppEmulation as AppEmulation;
/**
* Defines the implementaiton class of the WishlistManagementInterface
*/
class WishlistManagement implements WishlistManagementInterface
bool
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function addWishlistForCustomer($customerId, $productId)

if ($productId == null)
throw new LocalizedException(__
('Invalid product, Please select a valid product'));

try
$product = $this->_productRepository->getById($productId);
catch (NoSuchEntityException $e)
$product = null;

try
$wishlist = $this->_wishlistRepository->create()->loadByCustomerId
($customerId, true);
$wishlist->addNewItem($product);
$returnData = $wishlist->save();
catch (NoSuchEntityException $e)


return true;


/**
* Helper function that provides full cache image url
* @param MagentoCatalogModelProduct
* @return string
*/
public function getImageUrl($product, string $imageType = '')
$storeId = $this->storemanagerinterface->getStore()->getId();
$this->appEmulation->startEnvironmentEmulation($storeId, MagentoFrameworkAppArea::AREA_FRONTEND, true);
$imageUrl = $this->productImageHelper->create()->init($product, $imageType)->getUrl();
$this->appEmulation->stopEnvironmentEmulation();

return $imageUrl;





  1. Please execute deploy commands upgade and compile etc..


  2. Open postman app and test the same.
    enter image description here




Please let me know whether you have any questions?






share|improve this answer

























  • how to pass dynamic customer id ?customer_id=416 can i pass any variable instead 416

    – Sarvesh Tiwari
    yesterday


















0














You can read guide about REST API.
http://alankent.me/2015/07/24/creating-a-new-rest-web-service-in-magento-2/



I read & practice and now I can do anything about REST API.






share|improve this answer























  • Isn't there any api for wishlist directly?

    – Sujay Naik
    Apr 6 '16 at 6:58











  • hum, you read to reference, it's helpful for you.

    – MrTo-Kane
    Apr 6 '16 at 7:12











  • anyways thnx a lot

    – Sujay Naik
    Apr 6 '16 at 7:44











  • MagentoOdoo.com i tried that but ended up with : "message": "Request does not match any route.", "trace": null i tried the 1st example from : alankent.me/2015/07/24/…

    – Sujay Naik
    Apr 21 '16 at 6:07



















0














Wishlist is integral part for any eCommerce platform and We wish Magento guys would have included them in the core features. So we have taken the initiative and added these features by taking out the fork from the github. We are waiting for Magento guys to Merge our pull request. In the meanwhile you can take use the following forks for your online store:



WishList: https://github.com/manish-ip/magento2



Or you can download our free plugin from the following link :



WishList API Plugin: http://www.ipragmatech.com/products/wishlist-rest-api-magento/






share|improve this answer























  • I started to process your Pull Request github.com/magento/magento2/pull/5233 and made a Code Review of your proposed changes for Wishlist API. Here you can read main considerations you should apply to make us merge current PR - github.com/magento/magento2/pull/…

    – Igor Minyaylo
    Feb 23 '17 at 13:22



















0














Try this it will help to you.



/**
* Add wishlist item for the customer
* @param int $customerId
* @param int $productIdId
* @return array|bool
* @throws MagentoFrameworkExceptionLocalizedException
*/
public function addWishlistForCustomer($customerId, $productId)

if ($productId == null)
throw new LocalizedException(__
('Invalid product, Please select a valid product'));

try
$product = $this->_productRepository->getById($productId);
catch (NoSuchEntityException $e)
$product = null;

try
$wishlist = $this->_wishlistRepository->create()->loadByCustomerId
($customerId, true);
$wishlist->addNewItem($product);
$returnData = $wishlist->save();
catch (NoSuchEntityException $e)


return true;






share|improve this answer
























    Your Answer








    StackExchange.ready(function()
    var channelOptions =
    tags: "".split(" "),
    id: "479"
    ;
    initTagRenderer("".split(" "), "".split(" "), channelOptions);

    StackExchange.using("externalEditor", function()
    // Have to fire editor after snippets, if snippets enabled
    if (StackExchange.settings.snippets.snippetsEnabled)
    StackExchange.using("snippets", function()
    createEditor();
    );

    else
    createEditor();

    );

    function createEditor()
    StackExchange.prepareEditor(
    heartbeatType: 'answer',
    autoActivateHeartbeat: false,
    convertImagesToLinks: false,
    noModals: true,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    imageUploader:
    brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
    contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
    allowUrls: true
    ,
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );













    draft saved

    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f109651%2fneed-rest-api-for-add-to-wishlist-in-magento-2%23new-answer', 'question_page');

    );

    Post as a guest















    Required, but never shown

























    4 Answers
    4






    active

    oldest

    votes








    4 Answers
    4






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes









    2















    1. Create a module Test_Mobileshop



    Please follow the below steps with the file paths




    2.app/code/Test/Mobileshop/etc/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/items" method="GET">
    <service class="TestMobileshopApiWishlistManagementInterface" method="getWishlistForCustomer"/>
    <resources>
    <resource ref="anonymous" />
    </resources>
    <data>
    <parameter name="customerId" force="true">%customer_id%</parameter>
    </data>
    </route>
    <route url="/V1/wishlist/add/:productId" method="POST">
    <service class="TestMobileshopApiWishlistManagementInterface" method="addWishlistForCustomer"/>
    <resources>
    <resource ref="anonymous" />
    </resources>
    <data>
    <parameter name="customerId" force="true">%customer_id%</parameter>
    </data>
    </route>
    </routes>



    1. app/code/Test/Mobileshop/etc/di.xml



    <?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="TestMobileshopApiWishlistManagementInterface" type="TestMobileshopModelWishlistManagement" />
    </config>



    1. app/code/Test/Mobileshop/Api/WishlistManagementInterface.php



    <?php
    /**
    * A Magento 2 module named Test/Mobileshop
    *
    */
    namespace TestMobileshopApi;

    /**
    * Interface WishlistManagementInterface
    * @api
    */
    interface WishlistManagementInterface


    /**
    * Return Wishlist items.
    *
    * @param int $customerId
    * @return array
    */
    public function getWishlistForCustomer($customerId);

    /**
    * Return Added wishlist item.
    *
    * @param int $customerId
    * @param int $productId
    * @return array
    *
    */
    public function addWishlistForCustomer($customerId,$productId);





    1. app/code/Test/Mobileshop/Model/WishlistManagement.php



    <?php
    /**
    * A Magento 2 module named Test/Mobileshop
    *
    */
    namespace TestMobileshopModel;

    use TestMobileshopApiWishlistManagementInterface;
    use MagentoWishlistControllerWishlistProvider;
    use MagentoWishlistModelResourceModelItemCollectionFactory;
    use MagentoWishlistModelWishlistFactory;
    use MagentoCatalogApiProductRepositoryInterface;
    use MagentoFrameworkExceptionLocalizedException;
    use MagentoCatalogHelperImageFactory as ProductImageHelper;
    use MagentoStoreModelAppEmulation as AppEmulation;
    /**
    * Defines the implementaiton class of the WishlistManagementInterface
    */
    class WishlistManagement implements WishlistManagementInterface
    bool
    * @throws MagentoFrameworkExceptionLocalizedException
    */
    public function addWishlistForCustomer($customerId, $productId)

    if ($productId == null)
    throw new LocalizedException(__
    ('Invalid product, Please select a valid product'));

    try
    $product = $this->_productRepository->getById($productId);
    catch (NoSuchEntityException $e)
    $product = null;

    try
    $wishlist = $this->_wishlistRepository->create()->loadByCustomerId
    ($customerId, true);
    $wishlist->addNewItem($product);
    $returnData = $wishlist->save();
    catch (NoSuchEntityException $e)


    return true;


    /**
    * Helper function that provides full cache image url
    * @param MagentoCatalogModelProduct
    * @return string
    */
    public function getImageUrl($product, string $imageType = '')
    $storeId = $this->storemanagerinterface->getStore()->getId();
    $this->appEmulation->startEnvironmentEmulation($storeId, MagentoFrameworkAppArea::AREA_FRONTEND, true);
    $imageUrl = $this->productImageHelper->create()->init($product, $imageType)->getUrl();
    $this->appEmulation->stopEnvironmentEmulation();

    return $imageUrl;





    1. Please execute deploy commands upgade and compile etc..


    2. Open postman app and test the same.
      enter image description here




    Please let me know whether you have any questions?






    share|improve this answer

























    • how to pass dynamic customer id ?customer_id=416 can i pass any variable instead 416

      – Sarvesh Tiwari
      yesterday















    2















    1. Create a module Test_Mobileshop



    Please follow the below steps with the file paths




    2.app/code/Test/Mobileshop/etc/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/items" method="GET">
    <service class="TestMobileshopApiWishlistManagementInterface" method="getWishlistForCustomer"/>
    <resources>
    <resource ref="anonymous" />
    </resources>
    <data>
    <parameter name="customerId" force="true">%customer_id%</parameter>
    </data>
    </route>
    <route url="/V1/wishlist/add/:productId" method="POST">
    <service class="TestMobileshopApiWishlistManagementInterface" method="addWishlistForCustomer"/>
    <resources>
    <resource ref="anonymous" />
    </resources>
    <data>
    <parameter name="customerId" force="true">%customer_id%</parameter>
    </data>
    </route>
    </routes>



    1. app/code/Test/Mobileshop/etc/di.xml



    <?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="TestMobileshopApiWishlistManagementInterface" type="TestMobileshopModelWishlistManagement" />
    </config>



    1. app/code/Test/Mobileshop/Api/WishlistManagementInterface.php



    <?php
    /**
    * A Magento 2 module named Test/Mobileshop
    *
    */
    namespace TestMobileshopApi;

    /**
    * Interface WishlistManagementInterface
    * @api
    */
    interface WishlistManagementInterface


    /**
    * Return Wishlist items.
    *
    * @param int $customerId
    * @return array
    */
    public function getWishlistForCustomer($customerId);

    /**
    * Return Added wishlist item.
    *
    * @param int $customerId
    * @param int $productId
    * @return array
    *
    */
    public function addWishlistForCustomer($customerId,$productId);





    1. app/code/Test/Mobileshop/Model/WishlistManagement.php



    <?php
    /**
    * A Magento 2 module named Test/Mobileshop
    *
    */
    namespace TestMobileshopModel;

    use TestMobileshopApiWishlistManagementInterface;
    use MagentoWishlistControllerWishlistProvider;
    use MagentoWishlistModelResourceModelItemCollectionFactory;
    use MagentoWishlistModelWishlistFactory;
    use MagentoCatalogApiProductRepositoryInterface;
    use MagentoFrameworkExceptionLocalizedException;
    use MagentoCatalogHelperImageFactory as ProductImageHelper;
    use MagentoStoreModelAppEmulation as AppEmulation;
    /**
    * Defines the implementaiton class of the WishlistManagementInterface
    */
    class WishlistManagement implements WishlistManagementInterface
    bool
    * @throws MagentoFrameworkExceptionLocalizedException
    */
    public function addWishlistForCustomer($customerId, $productId)

    if ($productId == null)
    throw new LocalizedException(__
    ('Invalid product, Please select a valid product'));

    try
    $product = $this->_productRepository->getById($productId);
    catch (NoSuchEntityException $e)
    $product = null;

    try
    $wishlist = $this->_wishlistRepository->create()->loadByCustomerId
    ($customerId, true);
    $wishlist->addNewItem($product);
    $returnData = $wishlist->save();
    catch (NoSuchEntityException $e)


    return true;


    /**
    * Helper function that provides full cache image url
    * @param MagentoCatalogModelProduct
    * @return string
    */
    public function getImageUrl($product, string $imageType = '')
    $storeId = $this->storemanagerinterface->getStore()->getId();
    $this->appEmulation->startEnvironmentEmulation($storeId, MagentoFrameworkAppArea::AREA_FRONTEND, true);
    $imageUrl = $this->productImageHelper->create()->init($product, $imageType)->getUrl();
    $this->appEmulation->stopEnvironmentEmulation();

    return $imageUrl;





    1. Please execute deploy commands upgade and compile etc..


    2. Open postman app and test the same.
      enter image description here




    Please let me know whether you have any questions?






    share|improve this answer

























    • how to pass dynamic customer id ?customer_id=416 can i pass any variable instead 416

      – Sarvesh Tiwari
      yesterday













    2












    2








    2








    1. Create a module Test_Mobileshop



    Please follow the below steps with the file paths




    2.app/code/Test/Mobileshop/etc/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/items" method="GET">
    <service class="TestMobileshopApiWishlistManagementInterface" method="getWishlistForCustomer"/>
    <resources>
    <resource ref="anonymous" />
    </resources>
    <data>
    <parameter name="customerId" force="true">%customer_id%</parameter>
    </data>
    </route>
    <route url="/V1/wishlist/add/:productId" method="POST">
    <service class="TestMobileshopApiWishlistManagementInterface" method="addWishlistForCustomer"/>
    <resources>
    <resource ref="anonymous" />
    </resources>
    <data>
    <parameter name="customerId" force="true">%customer_id%</parameter>
    </data>
    </route>
    </routes>



    1. app/code/Test/Mobileshop/etc/di.xml



    <?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="TestMobileshopApiWishlistManagementInterface" type="TestMobileshopModelWishlistManagement" />
    </config>



    1. app/code/Test/Mobileshop/Api/WishlistManagementInterface.php



    <?php
    /**
    * A Magento 2 module named Test/Mobileshop
    *
    */
    namespace TestMobileshopApi;

    /**
    * Interface WishlistManagementInterface
    * @api
    */
    interface WishlistManagementInterface


    /**
    * Return Wishlist items.
    *
    * @param int $customerId
    * @return array
    */
    public function getWishlistForCustomer($customerId);

    /**
    * Return Added wishlist item.
    *
    * @param int $customerId
    * @param int $productId
    * @return array
    *
    */
    public function addWishlistForCustomer($customerId,$productId);





    1. app/code/Test/Mobileshop/Model/WishlistManagement.php



    <?php
    /**
    * A Magento 2 module named Test/Mobileshop
    *
    */
    namespace TestMobileshopModel;

    use TestMobileshopApiWishlistManagementInterface;
    use MagentoWishlistControllerWishlistProvider;
    use MagentoWishlistModelResourceModelItemCollectionFactory;
    use MagentoWishlistModelWishlistFactory;
    use MagentoCatalogApiProductRepositoryInterface;
    use MagentoFrameworkExceptionLocalizedException;
    use MagentoCatalogHelperImageFactory as ProductImageHelper;
    use MagentoStoreModelAppEmulation as AppEmulation;
    /**
    * Defines the implementaiton class of the WishlistManagementInterface
    */
    class WishlistManagement implements WishlistManagementInterface
    bool
    * @throws MagentoFrameworkExceptionLocalizedException
    */
    public function addWishlistForCustomer($customerId, $productId)

    if ($productId == null)
    throw new LocalizedException(__
    ('Invalid product, Please select a valid product'));

    try
    $product = $this->_productRepository->getById($productId);
    catch (NoSuchEntityException $e)
    $product = null;

    try
    $wishlist = $this->_wishlistRepository->create()->loadByCustomerId
    ($customerId, true);
    $wishlist->addNewItem($product);
    $returnData = $wishlist->save();
    catch (NoSuchEntityException $e)


    return true;


    /**
    * Helper function that provides full cache image url
    * @param MagentoCatalogModelProduct
    * @return string
    */
    public function getImageUrl($product, string $imageType = '')
    $storeId = $this->storemanagerinterface->getStore()->getId();
    $this->appEmulation->startEnvironmentEmulation($storeId, MagentoFrameworkAppArea::AREA_FRONTEND, true);
    $imageUrl = $this->productImageHelper->create()->init($product, $imageType)->getUrl();
    $this->appEmulation->stopEnvironmentEmulation();

    return $imageUrl;





    1. Please execute deploy commands upgade and compile etc..


    2. Open postman app and test the same.
      enter image description here




    Please let me know whether you have any questions?






    share|improve this answer
















    1. Create a module Test_Mobileshop



    Please follow the below steps with the file paths




    2.app/code/Test/Mobileshop/etc/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/items" method="GET">
    <service class="TestMobileshopApiWishlistManagementInterface" method="getWishlistForCustomer"/>
    <resources>
    <resource ref="anonymous" />
    </resources>
    <data>
    <parameter name="customerId" force="true">%customer_id%</parameter>
    </data>
    </route>
    <route url="/V1/wishlist/add/:productId" method="POST">
    <service class="TestMobileshopApiWishlistManagementInterface" method="addWishlistForCustomer"/>
    <resources>
    <resource ref="anonymous" />
    </resources>
    <data>
    <parameter name="customerId" force="true">%customer_id%</parameter>
    </data>
    </route>
    </routes>



    1. app/code/Test/Mobileshop/etc/di.xml



    <?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="TestMobileshopApiWishlistManagementInterface" type="TestMobileshopModelWishlistManagement" />
    </config>



    1. app/code/Test/Mobileshop/Api/WishlistManagementInterface.php



    <?php
    /**
    * A Magento 2 module named Test/Mobileshop
    *
    */
    namespace TestMobileshopApi;

    /**
    * Interface WishlistManagementInterface
    * @api
    */
    interface WishlistManagementInterface


    /**
    * Return Wishlist items.
    *
    * @param int $customerId
    * @return array
    */
    public function getWishlistForCustomer($customerId);

    /**
    * Return Added wishlist item.
    *
    * @param int $customerId
    * @param int $productId
    * @return array
    *
    */
    public function addWishlistForCustomer($customerId,$productId);





    1. app/code/Test/Mobileshop/Model/WishlistManagement.php



    <?php
    /**
    * A Magento 2 module named Test/Mobileshop
    *
    */
    namespace TestMobileshopModel;

    use TestMobileshopApiWishlistManagementInterface;
    use MagentoWishlistControllerWishlistProvider;
    use MagentoWishlistModelResourceModelItemCollectionFactory;
    use MagentoWishlistModelWishlistFactory;
    use MagentoCatalogApiProductRepositoryInterface;
    use MagentoFrameworkExceptionLocalizedException;
    use MagentoCatalogHelperImageFactory as ProductImageHelper;
    use MagentoStoreModelAppEmulation as AppEmulation;
    /**
    * Defines the implementaiton class of the WishlistManagementInterface
    */
    class WishlistManagement implements WishlistManagementInterface
    bool
    * @throws MagentoFrameworkExceptionLocalizedException
    */
    public function addWishlistForCustomer($customerId, $productId)

    if ($productId == null)
    throw new LocalizedException(__
    ('Invalid product, Please select a valid product'));

    try
    $product = $this->_productRepository->getById($productId);
    catch (NoSuchEntityException $e)
    $product = null;

    try
    $wishlist = $this->_wishlistRepository->create()->loadByCustomerId
    ($customerId, true);
    $wishlist->addNewItem($product);
    $returnData = $wishlist->save();
    catch (NoSuchEntityException $e)


    return true;


    /**
    * Helper function that provides full cache image url
    * @param MagentoCatalogModelProduct
    * @return string
    */
    public function getImageUrl($product, string $imageType = '')
    $storeId = $this->storemanagerinterface->getStore()->getId();
    $this->appEmulation->startEnvironmentEmulation($storeId, MagentoFrameworkAppArea::AREA_FRONTEND, true);
    $imageUrl = $this->productImageHelper->create()->init($product, $imageType)->getUrl();
    $this->appEmulation->stopEnvironmentEmulation();

    return $imageUrl;





    1. Please execute deploy commands upgade and compile etc..


    2. Open postman app and test the same.
      enter image description here




    Please let me know whether you have any questions?







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited yesterday

























    answered Dec 7 '18 at 4:24









    Nagaraju KasaNagaraju Kasa

    2,73221541




    2,73221541












    • how to pass dynamic customer id ?customer_id=416 can i pass any variable instead 416

      – Sarvesh Tiwari
      yesterday

















    • how to pass dynamic customer id ?customer_id=416 can i pass any variable instead 416

      – Sarvesh Tiwari
      yesterday
















    how to pass dynamic customer id ?customer_id=416 can i pass any variable instead 416

    – Sarvesh Tiwari
    yesterday





    how to pass dynamic customer id ?customer_id=416 can i pass any variable instead 416

    – Sarvesh Tiwari
    yesterday













    0














    You can read guide about REST API.
    http://alankent.me/2015/07/24/creating-a-new-rest-web-service-in-magento-2/



    I read & practice and now I can do anything about REST API.






    share|improve this answer























    • Isn't there any api for wishlist directly?

      – Sujay Naik
      Apr 6 '16 at 6:58











    • hum, you read to reference, it's helpful for you.

      – MrTo-Kane
      Apr 6 '16 at 7:12











    • anyways thnx a lot

      – Sujay Naik
      Apr 6 '16 at 7:44











    • MagentoOdoo.com i tried that but ended up with : "message": "Request does not match any route.", "trace": null i tried the 1st example from : alankent.me/2015/07/24/…

      – Sujay Naik
      Apr 21 '16 at 6:07
















    0














    You can read guide about REST API.
    http://alankent.me/2015/07/24/creating-a-new-rest-web-service-in-magento-2/



    I read & practice and now I can do anything about REST API.






    share|improve this answer























    • Isn't there any api for wishlist directly?

      – Sujay Naik
      Apr 6 '16 at 6:58











    • hum, you read to reference, it's helpful for you.

      – MrTo-Kane
      Apr 6 '16 at 7:12











    • anyways thnx a lot

      – Sujay Naik
      Apr 6 '16 at 7:44











    • MagentoOdoo.com i tried that but ended up with : "message": "Request does not match any route.", "trace": null i tried the 1st example from : alankent.me/2015/07/24/…

      – Sujay Naik
      Apr 21 '16 at 6:07














    0












    0








    0







    You can read guide about REST API.
    http://alankent.me/2015/07/24/creating-a-new-rest-web-service-in-magento-2/



    I read & practice and now I can do anything about REST API.






    share|improve this answer













    You can read guide about REST API.
    http://alankent.me/2015/07/24/creating-a-new-rest-web-service-in-magento-2/



    I read & practice and now I can do anything about REST API.







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Apr 6 '16 at 6:51









    MrTo-KaneMrTo-Kane

    1,77162465




    1,77162465












    • Isn't there any api for wishlist directly?

      – Sujay Naik
      Apr 6 '16 at 6:58











    • hum, you read to reference, it's helpful for you.

      – MrTo-Kane
      Apr 6 '16 at 7:12











    • anyways thnx a lot

      – Sujay Naik
      Apr 6 '16 at 7:44











    • MagentoOdoo.com i tried that but ended up with : "message": "Request does not match any route.", "trace": null i tried the 1st example from : alankent.me/2015/07/24/…

      – Sujay Naik
      Apr 21 '16 at 6:07


















    • Isn't there any api for wishlist directly?

      – Sujay Naik
      Apr 6 '16 at 6:58











    • hum, you read to reference, it's helpful for you.

      – MrTo-Kane
      Apr 6 '16 at 7:12











    • anyways thnx a lot

      – Sujay Naik
      Apr 6 '16 at 7:44











    • MagentoOdoo.com i tried that but ended up with : "message": "Request does not match any route.", "trace": null i tried the 1st example from : alankent.me/2015/07/24/…

      – Sujay Naik
      Apr 21 '16 at 6:07

















    Isn't there any api for wishlist directly?

    – Sujay Naik
    Apr 6 '16 at 6:58





    Isn't there any api for wishlist directly?

    – Sujay Naik
    Apr 6 '16 at 6:58













    hum, you read to reference, it's helpful for you.

    – MrTo-Kane
    Apr 6 '16 at 7:12





    hum, you read to reference, it's helpful for you.

    – MrTo-Kane
    Apr 6 '16 at 7:12













    anyways thnx a lot

    – Sujay Naik
    Apr 6 '16 at 7:44





    anyways thnx a lot

    – Sujay Naik
    Apr 6 '16 at 7:44













    MagentoOdoo.com i tried that but ended up with : "message": "Request does not match any route.", "trace": null i tried the 1st example from : alankent.me/2015/07/24/…

    – Sujay Naik
    Apr 21 '16 at 6:07






    MagentoOdoo.com i tried that but ended up with : "message": "Request does not match any route.", "trace": null i tried the 1st example from : alankent.me/2015/07/24/…

    – Sujay Naik
    Apr 21 '16 at 6:07












    0














    Wishlist is integral part for any eCommerce platform and We wish Magento guys would have included them in the core features. So we have taken the initiative and added these features by taking out the fork from the github. We are waiting for Magento guys to Merge our pull request. In the meanwhile you can take use the following forks for your online store:



    WishList: https://github.com/manish-ip/magento2



    Or you can download our free plugin from the following link :



    WishList API Plugin: http://www.ipragmatech.com/products/wishlist-rest-api-magento/






    share|improve this answer























    • I started to process your Pull Request github.com/magento/magento2/pull/5233 and made a Code Review of your proposed changes for Wishlist API. Here you can read main considerations you should apply to make us merge current PR - github.com/magento/magento2/pull/…

      – Igor Minyaylo
      Feb 23 '17 at 13:22
















    0














    Wishlist is integral part for any eCommerce platform and We wish Magento guys would have included them in the core features. So we have taken the initiative and added these features by taking out the fork from the github. We are waiting for Magento guys to Merge our pull request. In the meanwhile you can take use the following forks for your online store:



    WishList: https://github.com/manish-ip/magento2



    Or you can download our free plugin from the following link :



    WishList API Plugin: http://www.ipragmatech.com/products/wishlist-rest-api-magento/






    share|improve this answer























    • I started to process your Pull Request github.com/magento/magento2/pull/5233 and made a Code Review of your proposed changes for Wishlist API. Here you can read main considerations you should apply to make us merge current PR - github.com/magento/magento2/pull/…

      – Igor Minyaylo
      Feb 23 '17 at 13:22














    0












    0








    0







    Wishlist is integral part for any eCommerce platform and We wish Magento guys would have included them in the core features. So we have taken the initiative and added these features by taking out the fork from the github. We are waiting for Magento guys to Merge our pull request. In the meanwhile you can take use the following forks for your online store:



    WishList: https://github.com/manish-ip/magento2



    Or you can download our free plugin from the following link :



    WishList API Plugin: http://www.ipragmatech.com/products/wishlist-rest-api-magento/






    share|improve this answer













    Wishlist is integral part for any eCommerce platform and We wish Magento guys would have included them in the core features. So we have taken the initiative and added these features by taking out the fork from the github. We are waiting for Magento guys to Merge our pull request. In the meanwhile you can take use the following forks for your online store:



    WishList: https://github.com/manish-ip/magento2



    Or you can download our free plugin from the following link :



    WishList API Plugin: http://www.ipragmatech.com/products/wishlist-rest-api-magento/







    share|improve this answer












    share|improve this answer



    share|improve this answer










    answered Jun 22 '16 at 11:49







    user40382



















    • I started to process your Pull Request github.com/magento/magento2/pull/5233 and made a Code Review of your proposed changes for Wishlist API. Here you can read main considerations you should apply to make us merge current PR - github.com/magento/magento2/pull/…

      – Igor Minyaylo
      Feb 23 '17 at 13:22


















    • I started to process your Pull Request github.com/magento/magento2/pull/5233 and made a Code Review of your proposed changes for Wishlist API. Here you can read main considerations you should apply to make us merge current PR - github.com/magento/magento2/pull/…

      – Igor Minyaylo
      Feb 23 '17 at 13:22

















    I started to process your Pull Request github.com/magento/magento2/pull/5233 and made a Code Review of your proposed changes for Wishlist API. Here you can read main considerations you should apply to make us merge current PR - github.com/magento/magento2/pull/…

    – Igor Minyaylo
    Feb 23 '17 at 13:22






    I started to process your Pull Request github.com/magento/magento2/pull/5233 and made a Code Review of your proposed changes for Wishlist API. Here you can read main considerations you should apply to make us merge current PR - github.com/magento/magento2/pull/…

    – Igor Minyaylo
    Feb 23 '17 at 13:22












    0














    Try this it will help to you.



    /**
    * Add wishlist item for the customer
    * @param int $customerId
    * @param int $productIdId
    * @return array|bool
    * @throws MagentoFrameworkExceptionLocalizedException
    */
    public function addWishlistForCustomer($customerId, $productId)

    if ($productId == null)
    throw new LocalizedException(__
    ('Invalid product, Please select a valid product'));

    try
    $product = $this->_productRepository->getById($productId);
    catch (NoSuchEntityException $e)
    $product = null;

    try
    $wishlist = $this->_wishlistRepository->create()->loadByCustomerId
    ($customerId, true);
    $wishlist->addNewItem($product);
    $returnData = $wishlist->save();
    catch (NoSuchEntityException $e)


    return true;






    share|improve this answer





























      0














      Try this it will help to you.



      /**
      * Add wishlist item for the customer
      * @param int $customerId
      * @param int $productIdId
      * @return array|bool
      * @throws MagentoFrameworkExceptionLocalizedException
      */
      public function addWishlistForCustomer($customerId, $productId)

      if ($productId == null)
      throw new LocalizedException(__
      ('Invalid product, Please select a valid product'));

      try
      $product = $this->_productRepository->getById($productId);
      catch (NoSuchEntityException $e)
      $product = null;

      try
      $wishlist = $this->_wishlistRepository->create()->loadByCustomerId
      ($customerId, true);
      $wishlist->addNewItem($product);
      $returnData = $wishlist->save();
      catch (NoSuchEntityException $e)


      return true;






      share|improve this answer



























        0












        0








        0







        Try this it will help to you.



        /**
        * Add wishlist item for the customer
        * @param int $customerId
        * @param int $productIdId
        * @return array|bool
        * @throws MagentoFrameworkExceptionLocalizedException
        */
        public function addWishlistForCustomer($customerId, $productId)

        if ($productId == null)
        throw new LocalizedException(__
        ('Invalid product, Please select a valid product'));

        try
        $product = $this->_productRepository->getById($productId);
        catch (NoSuchEntityException $e)
        $product = null;

        try
        $wishlist = $this->_wishlistRepository->create()->loadByCustomerId
        ($customerId, true);
        $wishlist->addNewItem($product);
        $returnData = $wishlist->save();
        catch (NoSuchEntityException $e)


        return true;






        share|improve this answer















        Try this it will help to you.



        /**
        * Add wishlist item for the customer
        * @param int $customerId
        * @param int $productIdId
        * @return array|bool
        * @throws MagentoFrameworkExceptionLocalizedException
        */
        public function addWishlistForCustomer($customerId, $productId)

        if ($productId == null)
        throw new LocalizedException(__
        ('Invalid product, Please select a valid product'));

        try
        $product = $this->_productRepository->getById($productId);
        catch (NoSuchEntityException $e)
        $product = null;

        try
        $wishlist = $this->_wishlistRepository->create()->loadByCustomerId
        ($customerId, true);
        $wishlist->addNewItem($product);
        $returnData = $wishlist->save();
        catch (NoSuchEntityException $e)


        return true;







        share|improve this answer














        share|improve this answer



        share|improve this answer








        edited Oct 5 '18 at 4:42









        Chirag Patel

        2,368423




        2,368423










        answered Oct 5 '18 at 4:10









        Anh TrầnAnh Trần

        1




        1



























            draft saved

            draft discarded
















































            Thanks for contributing an answer to Magento Stack Exchange!


            • Please be sure to answer the question. Provide details and share your research!

            But avoid


            • Asking for help, clarification, or responding to other answers.

            • Making statements based on opinion; back them up with references or personal experience.

            To learn more, see our tips on writing great answers.




            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fmagento.stackexchange.com%2fquestions%2f109651%2fneed-rest-api-for-add-to-wishlist-in-magento-2%23new-answer', 'question_page');

            );

            Post as a guest















            Required, but never shown





















































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown

































            Required, but never shown














            Required, but never shown












            Required, but never shown







            Required, but never shown







            Popular posts from this blog

            Sum ergo cogito? 1 nng

            三茅街道4182Guuntc Dn precexpngmageondP