How to Add Products to Wishlist By GraphQL Mutation Magento 2?

addProductsToWishlist mutation to add any type of products in the wishlist using GraphQL Mutation Magento 2.

Before adding with mutation, Make sure the Wishlist feature is activated by settings.
Go to Admin panel, Click Left sidebar Stores -> Configuration.
Now Click on Customers Tab -> Wish List -> General Options -> Enable -> Yes.

You can check the syntax for the addProductsToWishlist from the schema file,

Supported Product Types to add wishlist mutation:

  • Simple
  • Virtual
  • Downloadable
  • Bundle
  • Configurable
  • Grouped
  • Gift card


Step to add a product to wishlist using GraphQL,

1.)Generate Customer Token and set it with Header Param Bearer value,
Authorization Bearer {CUSTOMER_TOKEN}

2) Wishlist GraphQL Mutation,

Once you run this mutation, two items will be added to the customer wishlist.

You can add single or multiple items at one time from the mutation.

wishlistItems{} The attribute contains the items list add to the wishlist.

1) Simple Product Items data structure,

2) Configurable Product Items data structure,

SKU is the product SKU and quantity are the no. of qty to add.

selected_options is the base64 encoded value for the child item of the configurable product which the user can select from the item.

Let us Describe it by example,
SKU MJ01 item with child item with Red Color and Size will be S.

Here child item with Color attribute id is 93 and the Red Value option id is 67.
Size attribute option id is 186 and the S Value option id is 176.

Based on the response of both the encoded value, we have to add it to the selected options array by each new separate line,

You can do the same Data structure for the different type of products also.