addConfigurableProductsToCart mutation

We recommend using the addProductsToCart mutation to add any type of product to the cart.

Use the addConfigurableProductsToCart mutation to add configurable products to a specific cart.

Syntax

mutation: {addConfigurableProductsToCart(input: AddConfigurableProductsToCartInput) {AddConfigurableProductsToCartOutput}}

Example usage

The following example adds two black Teton Pullover Hoodies size extra-small to the specified shopping cart. The cart_id used in this example was generated by creating an empty cart.

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
mutation {
  addConfigurableProductsToCart(
    input: {
      cart_id: "4JQaNVJokOpFxrykGVvYrjhiNv9qt31C"
      cart_items: [
        {
          parent_sku: "MH02"
          data: {
            quantity: 2
            sku: "MH02-XS-Black"
          }
        }
      ]
    }
  ) {
    cart {
      items {
        uid
        quantity
        product {
          name
          sku
        }
        ... on ConfigurableCartItem {
          configurable_options {
            option_label
          }
        }
      }
    }
  }
}

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
{
  "data": {
    "addConfigurableProductsToCart": {
      "cart": {
        "items": [
          {
            "uid": "Mzc=",
            "quantity": 2,
            "product": {
              "name": "Teton Pullover Hoodie",
              "sku": "MH02"
            },
            "configurable_options": [
              {
                "option_label": "Color"
              },
              {
                "option_label": "Size"
              }
            ]
          }
        ]
      }
    }
  }
}

Input attributes

AddConfigurableProductsToCartInput object

The AddConfigurableProductsToCartInput object contains the following attributes:

Attribute Type Description
cart_id String! The unique ID that identifies the customer’s cart
cart_items [ConfigurableProductCartItemInput] An array of configurable items to add to the cart

ConfigurableProductCartItemInput object

The ConfigurableProductCartItemInput object contains the following attributes:

Attribute Type Description
customizable_options CustomizableOptionInput An object that contains the ID and value of the product
data CartItemInput! An object that contains the quantity and SKU of the configurable product
parent_sku String The SKU of the simple product’s parent configurable product. If you do not specify this attribute, Magento treats the product being added to the cart as a simple product
variant_sku String Deprecated. Use CartItemInput.sku instead. The SKU of the simple product

CustomizableOptionInput object

The CustomizableOptionInput object contains the following attributes:

Attribute Data Type Description
id Int A unique ID assigned to the customizable option
value_string String! A value assigned to the customizable option

CartItemInput object

The CartItemInput object must contain the following attributes:

Attribute Data Type Description
entered_options [EnteredOptionInput!] An array of entered options for the base product, such as personalization text
parent_sku String For child products, the SKU of its parent product
quantity Float! The quantity of the item to add to the cart
selected_options [ID!] The selected options for the base product, such as color or size, using the unique ID for a customizable or configurable object such as CustomizableRadioOption, CustomizableDropDownOption, or ConfigurableProductOptionsValues
sku String! The sku of the product to be added to the cart

Output attributes

The AddConfigurableProductsToCartOutput object contains the Cart object.

Attribute Data Type Description
cart Cart! Describes the contents of the specified shopping cart

Cart object

Attribute Data Type Description
applied_coupon AppliedCoupon Deprecated. Use applied_coupons instead
applied_coupons [AppliedCoupon] An array of AppliedCoupon objects. Each object contains the code text attribute, which specifies the coupon code
applied_gift_cards [AppliedGiftCard] An array of AppliedGiftCard objects. An AppliedGiftCard object contains the code text attribute, which specifies the gift card code. applied_gift_cards is a Commerce-only attribute, defined in the GiftCardAccountGraphQl module
applied_reward_points RewardPointsAmount The amount of reward points applied to the cart
applied_store_credit AppliedStoreCredit Contains store credit information applied to the cart. applied_store_credit is a Commerce-only attribute, defined in the CustomerBalanceGraphQl module
available_gift_wrappings [GiftWrapping]! The list of available gift wrapping options for the cart
available_payment_methods [AvailablePaymentMethod] Available payment methods
billing_address BillingCartAddress Contains the billing address specified in the customer’s cart
email String The customer’s email address
gift_message GiftMessage A gift message added to the cart
gift_receipt_included Boolean! Indicates if the customer requested a gift receipt for the cart
gift_wrapping GiftWrapping The selected gift wrapping for the cart
id ID! The unique ID of the cart
is_virtual Boolean! Indicates whether the cart contains only virtual products
items [CartItemInterface] Contains the items in the customer’s cart
prices CartPrices Contains subtotals and totals
printed_card_included Boolean! Indicates if the customer requested a printed card for the cart
selected_payment_method SelectedPaymentMethod Selected payment method
shipping_addresses [ShippingCartAddress]! Contains one or more shipping addresses
total_quantity Float! Total Quantity of products in the cart

Cart query output provides more information about the Cart object.

Errors

Error Description
Could not find a cart with ID "XXX" The specified cart_id value does not exist in the quote_id_mask table.
Could not add the product with SKU configurable to the shopping cart: The product that was requested doesn't exist. Verify the product and try again. The simple product with the SKU specified in the data.sku attribute does not exist.
Could not find a product with SKU "XXX" The configurable product with SKU specified in the parent_sku argument does not exist.
Could not find specified product. The simple product specified in the data.sku argument is not assigned to the configurable product provided in the parent_sku attribute.
Required parameter "cart_id" is missing The cart_id argument was omitted or contains an empty value.
Required parameter "cart_items" is missing The cart_items argument was omitted or contains an empty array.
Required parameter "email" is missing The email argument was omitted or contains an empty value.
The requested qty is not available The requested quantity specified data.quantity is not available.