How to use discountAutomaticBasicCreate with specific products or collections?

Topic summary

A user encountered errors when attempting to apply automatic discounts to specific products using Shopify’s discountAutomaticBasicCreate GraphQL mutation.

Initial Problem:

  • Tried using products: [{ id: "gid://shopify/ProductVariant/..." }] but received a validation error expecting a key-value object
  • Also attempted productVariants field, which resulted in GraphQL errors indicating the field doesn’t exist

Solution Provided:
The correct syntax varies by use case:

  • All products: items: { all: true }
  • Specific products: items: { products: { productIds: ["gid://shopify/Product/..."] } }
  • Collections: items: { collections: { collectionIds: ["gid://shopify/Collection/..."] } }

Key Issue:
The user was referencing ProductVariant IDs instead of Product IDs, and using incorrect object structure. A working code example was provided showing proper mutation structure with nested productIds array within a products object.

Summarized with AI on October 29. AI used: claude-sonnet-4-5-20250929.

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
        }
      }
    }
  }
}