How to Get Cross Sell Products Using GraphQL in Magento 2

Do you want to get cross-sell products using GraphQL Query in Magento 2?

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

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

Let’s start!

You need to use below GraphQL query to get cross-sell products.

{
  products(filter: { sku: { eq: "24-WB04" } }) {
    items {
      id
      name
      sku
      crosssell_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 crosssell_products{} field which helps to get all the cross-sell products.

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

See below results.

How to Get Cross Sell Products Using GraphQL in Magento 2

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

How to Get Cross Sell 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 *