Automatic Discount function

Working on a custom logic for client’s problem, to provide automatic discount based on a line item property. I am trying to deploy the function and create it via graphql explorer app.
It works fine on the dev store, but on client’s production store, the query doesn’t run.
I know it is not restricted to Shopify plus.
But still i don’t get it why it is not creating an instance of the function

This is the mutation I’m running to create the instance of our function

mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {
  discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {
    userErrors {
      field
      message
    }
    automaticAppDiscount {
      discountId
      title
      startsAt
      endsAt
      status
      appDiscountType {
        appKey
        functionId
      }
      combinesWith {
        orderDiscounts
        productDiscounts
        shippingDiscounts
      }
    }
  }
}

Variables:

{
  "automaticAppDiscount": {
    "title": "Model is not listed",
    "functionId": "934f2f78-739f-4635-83a5-d69bc84dbb01",
    "startsAt": "2025-02-20T13:04:17.062Z",
    "endsAt": null,
    "combinesWith": {
      "orderDiscounts": true,
      "productDiscounts": true,
      "shippingDiscounts": true
    },
    "metafields": [
      {
        "namespace": "default",
        "key": "function-configuration",
        "type": "json",
        "value": "{\n  \"discounts\": [{\n    \"value\": {\"fixedAmount\": {\"amount\": 5}},\n    \"targets\": [{\"orderSubtotal\": {\"excludedVariantIds\": []}}]\n  }],\n  \"discountApplicationStrategy\": \"FIRST\"\n}"
      }
    ]
  }
}

Does the app have the write_discounts access scope?

Yes @Liam-Shopify , It has the write_discounts scope

We’re observing the same issue. Discount creation works in the dev store, but fails in the prod store with the internal server error. This happens even when only sending title, startsAt and functionId.

I think we need to bump this, because I’ve seen multiple threads at old community forum too, about the same issue, and it remains unresolved.

Can you post a recent error requestID so I can dig into this on my side?

Two examples:

  • 2712da10-72e1-488a-b070-4e864a41e01c-1740256296
  • f2b80fa1-f8ab-489a-96d2-812740e950f3-1739887909
1 Like

Hey Liam,
It would be very helpful if Shopify can provide a solution to this quickly. We have been stuck on it for days, and there is no other way to do the solution for our client.
and our client has been waiting for us to delivery it.
Please if you could give us an update good enough.
Thank you

Hey Shine,

Can you confirm what plan the store is on, where this is failing? It looks like this could be failing because the store is not on Plus, from our docs Shopify Functions are available on all plans when the app is a public app. If the app is not public, then only stores on Plus can use Functions from a custom app: About Shopify Function APIs

Is a custom app one that’s store-specific or also one that’s distributed via link? I’m using the latter.

Gotcha Liam,
That clears it up,
We are really limited now, as we can’t use public app without approval of shopify for listing and we can’t use custom app unless its Shopify plus.

@Liam-Shopify I find the communication around this confusing.

So just to be clear: there is no way to add dynamic discounts besides being on Plus and publishing the app to the store?

Why does the app work on a dev store, if one needs Plus in a non-dev store?

It will work on a test dev store because if you’re building a public app you’ll need a non-Plus environment to test it out in, since it will work on non-Plus stores as a public app.

There’s no mention of Plus in this guide: Build a product discount function

I’ll flag this to the docs team.

Why is a generic 500 thrown when this is about a limitation of the plan?

Good point - have reached out to the Discounts team to improve this.