How to Get Upsell Products Using GraphQL in Magento 2

Do you want to get upsell products using GraphQL Query in Magento 2?

If you want to get all the upsell products of the specific product using GraphQL, You will need to use the upsell product GraphQL Query to retrieve all those products.

In this tutorial we are going to show you how to get upsell products using GraphQL in Magento 2.

Let’s start!

You need to use below GraphQL query to get upsell products.

{
  products(filter: { sku: { eq: "24-WB04" } }) {
    items {
      id
      name
      sku
      upsell_products {
        id
        sku
        stock_status
        short_description {
          html
        }
        url_key
        name
        special_price
        price_range {
          minimum_price {
            final_price {
              value
              currency
            }
          }
          maximum_price {
            final_price {
              value
              currency
            }
          }
        }
      }
    }
  }
}

In the above GraphQL query, you can see upsell_products{} field which helps to get all the upsell products.

As per above given query, If the product with sku as “24-WB04” contains upsell products assigned, the output will have all the assigned products array with upsell_products key otherwise it will display an empty array.

See below results.

How to Get Upsell Products Using GraphQL in Magento 2

You can use ChromeiQL tool to test and run GraphQL Query in Magento 2.

How to Get Upsell Products Using GraphQL in Magento 2 Click To Tweet

If you liked this tutorial, then please subscribe to our Newsletter for Magento tutorials. You can also find us on Twitter and Facebook. If you have any problem or would like to add to the discussion, leave a comment below!

You May Also Like

Editorial Staff

About the Author: Editorial Staff

Editorial Staff at the MageBeginners is a team of Magento experts writing about Magento Tutorials, Themes, Extensions, Guides, Tricks and much more...

Leave a Reply

Your email address will not be published. Required fields are marked *