discountAutomaticAppCreate mutation broken in all API versions prior to 2025-04

Hi there,

It looks like there’s a bug in the discountAutomaticAppCreate mutation that’s required to create discount functions.

The latest API version 2025-04 introduced a discountClasses field in the input.

However, this field doesn’t exist in API versions prior to 2025-04, yet the mutation is requiring it.

Reproduction steps

For the following steps, I’ll reuse this same mutation definition:

// queries/createAppDiscount.js
import { gql } from "@apollo/client";

export default gql`
  mutation discountAutomaticAppCreate(
    $automaticAppDiscount: DiscountAutomaticAppInput!
  ) {
    discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {
      userErrors {
        field
        message
      }
      automaticAppDiscount {
        discountId
      }
    }
  }
`;

For example, if you use 2024-07 as your API version, and attempt to create a function as described in the documentation:

// Shopify API version 2024-07
await graphql.mutate({
    mutation: createAppDiscount,
    variables: {
      automaticAppDiscount: {
        title: "ID verification discount",
        functionId: "YOUR FUNCTION ID",
        startsAt: new Date().toISOString(),
        endsAt: null,
      },
    },
})

Results in this error that is trying to say that you need to define a discountClasses field:

    "discountAutomaticAppCreate": {
      "automaticAppDiscount": null,
      "userErrors": [
        {
          "field": [
            "automaticAppDiscount",
            "discountClasses"
          ],
          "message": "Discount classes is required for the discount Function.",
          "__typename": "DiscountUserError"
        }
      ],
      "__typename": "DiscountAutomaticAppCreatePayload"
    }

This field cannot be passed, because it doesn’t exist in any version prior to 2025-04.

If you attempt to pass the discountClasses, it will yell at you for passing a field that doesn’t exist yet:

// Shopify API version 2024-07
await graphql.mutate({
    mutation: createAppDiscount,
    variables: {
      automaticAppDiscount: {
        title: "ID verification discount",
        functionId: "YOUR FUNCTION ID",
        startsAt: new Date().toISOString(),
        endsAt: null,
        // adding discount codes like the error suggests to do:
       discountClasses: ["ORDER"],
      },
    },
})

This results in an error as well, because discountCodes doesn’t exist until the latest API version:

  graphQLErrors: [
    {
      message: 'Variable $automaticAppDiscount of type DiscountAutomaticAppInput! was provided invalid value for discountClasses (Field is not defined on DiscountAutomaticAppInput)',
      locations: [Array],
      extensions: [Object]
    }
  ],

Is it possible to have this bug addressed?

I’m not even able to find a changelog for 2025-04 to view breaking changes from 2025-01, so blindly upgrading is a bit too much risk for my taste.

Hey Dylan- thanks for the report.

This error occurs when trying to create a discount using a function with the new discounts API introduced in 2025-04, which requires the new discountClasses field and therefore the API version 2025-04. We’re working on making the messaging more clear for this scenario.

Discount functions using the product_discounts, order_discounts, and shipping_discounts API types should still be functional as normal on older API versions.

1 Like

Ah that definitely explains it.

So for now, when generating a new extension, we should choose one of the product/order/shipping discount options instead of the generation Discount Function option?

CleanShot 2025-04-17 at 10.16.58

Yes, I’d stick with those until you’re ready to move to 2025-04 :slightly_smiling_face:

You will be able to migrate from those older APIs to the new API (without any service disruption) once you’re ready for 2025-04- documentation to guide you through that process is on the way.

Thanks for your patience :folded_hands:

Thanks @Duncan_Uszkay that’s really helpful to know.

I just need to make the decision now to upgrade before rolling this feature out, so I don’t have to migrate again in the future or kick the can down the road.

We’re already upgraded to 2025-04, not on the new API, and don’t have any errors like this in production. However, I do now get this in development. I believe my workflow was:

‘upgrade’ to the new discount API, but then try to run against the older APIs, but I’m not 100% sure.

@Duncan_Uszkay - how safe is it to use the new Discount API in production today?