How to use discountAutomaticBasicCreate with specific products or collections?

How to use discountAutomaticBasicCreate with specific products or collections?

alfaiz2393
Shopify Partner
2 0 0

 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.






Reply 1 (1)

Small_Task_Help
Shopify Partner
969 38 93

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
        }
      }
    }
  }
}
To Get Shopify Experts Help, Click Here or E-mail - hi@ecommercesmalltask.com
About Us - We are Shopify Expert India
At Google My Business - Ecommerce Small Task - Hire Shopify Developers Ahmedabad