addProductsToWishlist mutation

The addProductsToWishlist mutation adds one or more products to the specified wish list. This mutation supports all product types.

In Magento Open Source, customers can have only one wish list. In Adobe Commerce, customers can have multiple wish lists.

In Magento Open Source, the createCustomerV2 mutation does not create a default wish list for the customer. To add items to the wish list for the first time, specify a wishlistId value of 0. Magento creates the customer’s default wish list and returns the wish list ID in the id attribute. (Customers created by any other means or in Adobe Commerce do not have this limitation.)

This mutation requires a valid customer authentication token.

To determine whether wish lists are enabled, specify the magento_wishlist_general_is_enabled attribute in the storeConfig query.

Syntax

1
2
3
4
5
6
7
8
`mutation {
  addProductsToWishlist(
    wishlistId: ID!,
    wishlistItems: [WishlistItemInput!]!
  ){
  AddProductsToWishlistOutput
  }
}

Example usage

The following example adds a simple product (24-MB01), a configurable product (WJ01-M-Red), and a bundle product (24-WG080) to the customer’s wish list. The SKU WG-09 is invalid, and error information is returned in the user_errors object.

To determine the value of the wishlistId attribute, run the customer query and check the value of wishlist.id in the response.

Request:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
mutation {
  addProductsToWishlist(
    wishlistId: 4
    wishlistItems: [
      {
        sku: "24-MB01"
        quantity: 1
      }
      {
        sku: "WG-09"
        quantity: 1
        }
      {
        parent_sku: "WJ01"
        sku: "WJ01-M-Red"
        quantity: 1
      }
      {
        sku: "24-WG080"
        quantity: 1
        selected_options: [
          "YnVuZGxlLzEvMS8x"
          "YnVuZGxlLzIvNC8x"
          "YnVuZGxlLzMvNy8x"
          "YnVuZGxlLzQvOC8x"
        ]
      }
    ]
  ) {
    wishlist {
      id
      items_count
      items_v2 (currentPage: 1, pageSize: 8 ) {
        items {
          id
          quantity
          ... on BundleWishlistItem {
            bundle_options {
              values {
                id
                label
                quantity
              }
            }
          }
          product {
            uid
            name
            sku
            price_range {
              minimum_price {
                regular_price {
                  currency
                  value
                }
              }
              maximum_price {
                regular_price {
                  currency
                  value
                }
              }
            }
          }
        }
      }
    }
    user_errors {
      code
      message
    }
  }
}

Response:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
{
  "data": {
    "addProductsToWishlist": {
      "wishlist": {
        "id": "4",
        "items_count": 3,
        "items_v2": {
          "items": [
            {
              "id": "20",
              "quantity": 1,
              "product": {
                "uid": "MQ==",
                "name": "Joust Duffle Bag",
                "sku": "24-MB01",
                "price_range": {
                  "minimum_price": {
                    "regular_price": {
                      "currency": "USD",
                      "value": 34
                    }
                  },
                  "maximum_price": {
                    "regular_price": {
                      "currency": "USD",
                      "value": 34
                    }
                  }
                }
              }
            },
            {
              "id": "21",
              "quantity": 1,
              "product": {
                "uid": "MTIyNg==",
                "name": "Stellar Solar Jacket",
                "sku": "WJ01",
                "price_range": {
                  "minimum_price": {
                    "regular_price": {
                      "currency": "USD",
                      "value": 75
                    }
                  },
                  "maximum_price": {
                    "regular_price": {
                      "currency": "USD",
                      "value": 75
                    }
                  }
                }
              }
            },
            {
              "id": "22",
              "quantity": 1,
              "bundle_options": [
                {
                  "values": [
                    {
                      "id": 1,
                      "label": "Sprite Stasis Ball 55 cm",
                      "quantity": 1
                    }
                  ]
                },
                {
                  "values": [
                    {
                      "id": 4,
                      "label": "Sprite Foam Yoga Brick",
                      "quantity": 1
                    }
                  ]
                },
                {
                  "values": [
                    {
                      "id": 7,
                      "label": "Sprite Yoga Strap 10 foot",
                      "quantity": 1
                    }
                  ]
                },
                {
                  "values": [
                    {
                      "id": 8,
                      "label": "Sprite Foam Roller",
                      "quantity": 1
                    }
                  ]
                }
              ],
              "product": {
                "uid": "NTI=",
                "name": "Sprite Yoga Companion Kit",
                "sku": "24-WG080",
                "price_range": {
                  "minimum_price": {
                    "regular_price": {
                      "currency": "USD",
                      "value": 61
                    }
                  },
                  "maximum_price": {
                    "regular_price": {
                      "currency": "USD",
                      "value": 77
                    }
                  }
                }
              }
            }
          ]
        }
      },
      "user_errors": [
        {
          "code": "PRODUCT_NOT_FOUND",
          "message": "Could not find a product with SKU \"WG-09\""
        }
      ]
    }
  }
}

Input attributes

The addProductsToWishlist mutation requires the following input.

Attribute Data Type Description
wishlistId ID! The ID of the customer’s wish list
wishlistItems [[WishlistItemInput(#WishlistItemInput)]!]! An array containing each product to be added to the wish list

WishlistItemInput attributes

The WishlistItemInput object defines each item to add to the wish list.

Attribute Data Type Description
entered_options [EnteredOptionInput!] An array of options that the customer entered
parent_sku String For complex product types, the SKU of the parent product
quantity Float! The amount or number of items to add
selected_options [ID] An array of strings corresponding to options the customer selected
sku String! The SKU of the product to add. For complex product types, specify the child product SKU

EnteredOptionInput attributes

The EnteredOptionInput object must contain the following attributes.

Attribute Data Type Description
uid ID! The unique ID for a specific CustomizableOptionInterface object, such as a CustomizableFieldOption, CustomizableFileOption, or CustomizableAreaOption object
value String! Text the customer entered

Output attributes

The AddProductsToWishlistOutput object contains the customer’s wish list and error message information.

Attribute Data Type Description
user_errors [WishListUserInputError!] An array of errors encountered while adding products to a wish list
wishlist Wishlist! Contains the wish list with all items that were successfully added

Wishlist attributes

The Wishlist object contains all the items in the customer’s wish list.

Attribute Data type Description
id ID The unique ID of a Wishlist object
items [WishlistItem] Deprecated. Use items_v2 instead
items_v2 [WishlistItemInterface] An array of items in the customer’s wish list
items_count Int The number of items in the wish list
name String The wish list name. Applicable to Adobe Commerce only
sharing_code String An encrypted code that Magento uses to link to the wish list
updated_at String The time of the last modification to the wish list
visibility WishlistVisibilityEnum! An enum indicating whether the wish list is PUBLIC or PRIVATE. Applicable to Adobe Commerce only

WishlistItem attributes

The WishlistItem object can contain the following attributes.

Attribute Data type Description
added_at String The time when the customer added the item to the wish list
description String The customer’s comment about this item
id Int The wish list item ID
product ProductInterface The ProductInterface contains attributes that are common to all types of products. Note that descriptions may not be available for custom and EAV attributes
qty Float The quantity of this wish list item

WishListUserInputError attributes

The WishListUserInputError object contains information about errors that are specific to wish lists.

Attribute Data Type Description
code WishListUserInputErrorType! A wish list-specific error code. Possible values include PRODUCT_NOT_FOUND and UNDEFINED
message String! A localized error message

Errors

Error Description
The current user cannot perform operations on wishlist An unauthorized user (guest) tried to add an item to a wishlist, or an authorized user (customer) tried to add an item to a wishlist belonging to another customer.
The wishlist was not found. The value provided in the wishlistId field is invalid or does not exist for the customer.