How To Add Downloadable Products By Using GraphQL in Magento 2.x / Adobe Commerce 2.x
Use the updateCartItems
mutation to update shopping cart items and removeItemFromCart
to remove a product from the shopping cart.
The following below steps need to follow to add Downloadable products by using GraphQL in Magento 2.x
Step [1] – Recommendation to use below Downloadable Product syntax
Here Using Postman
Syntax –
mutation {
addDownloadableProductsToCart(
input: AddDownloadableProductsToCartInput
) {
AddDownloadableProductsToCartOutput
}
}
Step [2] – Put below Request
mutation {
addDownloadableProductsToCart(
input: {
cart_id: "s6Wgi4j0H2ULX0YHfD3mhOMHuAL10qLL"
cart_items: {
data: {
sku: "Gaming-Software"
quantity: 1
}
downloadable_product_links: [
{
link_id: 7 # Episode 2
}
{
link_id: 8 # Episode 3
}
]
}
}
) {
cart {
items {
product {
id
sku
name
}
quantity
... on DownloadableCartItem {
links {
title
price
}
samples {
title
sample_url
}
}
}
}
}
}
Step [3] – Below output response
{
"data": {
"addDownloadableProductsToCart": {
"cart": {
"items": [
{
"product": {
"id": 2041,
"sku": "Gaming-Software",
"name": "Gaming-Software"
},
"quantity": 1,
"links": [
{
"title": "Gaming Software",
"price": 0
}
],
"samples": []
}
]
}
}
}
}