How to correctly use discountAutomaticBasicCreate mutation for applying discounts to all items, specific products, or collections?
I tried using this input for selected products:
items: {
products: [
{ id: “gid://shopify/ProductVariant/1234567890” },
{ id: “gid://shopify/ProductVariant/9876543210” },
]
}
But I’m getting the following error:
Variable $automaticBasicDiscount of type DiscountAutomaticBasicInput! was provided invalid value for customerGets.items.products (Expected […] to be a key-value object.)
I’ve also tried:
items: {
productVariants: [
{ id: “gid://shopify/ProductVariant/…” }
]
}
But that also caused GraphQL validation errors saying the field doesn’t exist.
Hi,
Hope this will help
-For all Products use items: { all: true } code
- Specific products use items: { products: { productIds: [ “gid://shopify/Product/…” ] } } code
- For collection use items: { collections: { collectionIds: [ “gid://shopify/Collection/…” ] } } code
Example: Apply 10% Discount to Specific Products
code eaxmple
mutation {
discountAutomaticBasicCreate(
automaticBasicDiscount: {
title: "10% Off Selected Products"
startsAt: "2025-04-09T00:00:00Z"
customerGets: {
value: {
percentage: 10
}
items: {
products: {
productIds: [
"gid://shopify/Product/1234567890",
"gid://shopify/Product/9876543210"
]
}
}
}
}
) {
userErrors {
field
message
}
automaticDiscountNode {
id
automaticDiscount {
... on DiscountAutomaticBasic {
title
status
}
}
}
}
}