GraphQL Discount Code

Hello,

In my store we added a discount code (Buy X get Y)
how i can receive a list of products that are include in this discount ?

Thanks.

Hi Yohad_h,

On the [doc page about managing existing discounts] there’s some great information on querying discounts with GraphQL, with a simplified example of how to get the list of products for Buy X Get Y Discount codes below put together mostly from the examples on that page.

Please note that this example only requests the first 25 codes as the query has a fairly [high query cost] due to its depth so in a store with many discounts it would be important to make use of [result pagination] and/or adjust the query so it costs less. Removing the ‘on DiscountCollections’ section would reduce the cost if it’s known that none of the discounts are collection specific or if that doesn’t matter.

Also this will only show discount codes and not automatic discounts as there’s a separate query for the automatic ones which works similarly called [automaticDiscountNodes].

It’s recommended to test the query and variations on it in the [Shopify GraphiQL App] to get a feel for how changes to it affect the query cost.

Example query:

{
codeDiscountNodes(first: 25, query: “discount_type:bogo”) {
nodes {
id
codeDiscount {
__typename
… on DiscountCodeBxgy {
status
title
customerGets {
items {
__typename
… on DiscountProducts {
productVariants(first: 10) {
nodes {
id
title
}
}
products(first: 10) {
nodes {
id
title
}
}
}
… on DiscountCollections {
collections(first: 10) {
nodes {
id
title
}
}
}
}
}
}
}
}
}
}

Related docs: