Admin GraphQL API discountAutomaticAppCreate mutation "Function not found" error

Topic summary

Main issue: discountAutomaticAppCreate returns “Function not found” or server errors when called outside the app template (e.g., via Postman) or on production stores.

Key clarifications:

  • An app can only reference its own Functions. The Admin API token used must belong to the same app that owns the functionId.
  • Use an offline Admin API access token (non-expiring OAuth token) for that same app when calling discountAutomaticAppCreate. Ensure required scopes (e.g., write_discounts).

Development vs production:

  • Several reports: works on development stores but fails on production (either “function not found” or INTERNAL_SERVER_ERROR).
  • Guidance indicates Functions in custom/single‑shop apps require a Shopify Plus subscription on the target shop. Non‑Plus production shops may fail even if development works. One user notes cart‑validation functions work; discount Functions may have stricter requirements.

Actionable steps:

  • Verify the token is an offline token issued to the same app as the function.
  • Confirm the target store’s plan supports custom app Functions (Plus for discounts).

Status/open items:

  • How to obtain the offline token is referenced via OAuth docs; no step‑by‑step in thread.
  • Internal server error on production remains unresolved beyond plan requirement guidance.
Summarized with AI on December 18. AI used: gpt-5.

I am creating discount app and using Shopify Functions Product Discount API to create discounts. I have used this template ( https://github.com/Shopify/function-examples/tree/main/sample-apps/discounts-tutorial ). It works well and created the app with product discounts extension. To create a discount itself it uses admin GraphQL API with discountAutomaticAppCreate mutation. All works when creating discounts from the app template. However, when I try to send the same request from Postman I am getting the following error:

Here is my mutation:

mutation CreateAutomaticAppDiscount($discount: DiscountAutomaticAppInput!) {
   discountAutomaticAppCreate(
     automaticAppDiscount: $discount
   ) {
     userErrors {
       code
       message
       field
     }
   }
 }
**Variables:**
{
  "discount": {
    "functionId": "FUNCTION_ID_FROM_APP",
    "title": "POSTMAN DISCOUNT",
    "combinesWith": {
      "orderDiscounts": false,
      "productDiscounts": true,
      "shippingDiscounts": true
    },
    "startsAt": "2022-08-11T14:23:27.757Z",
    "endsAt": null,
  }
}

It looks like API does not see my function. I checked the functionId, it’s correct.
I want to change the project template to a custom one, because of inconvenience and other problems. That is why I cannot continue using this template.

P.S. I tried to send the request from another app’s backend (working app) and received the same error.
All requests are done to the store with checkout extensibility preview.

Can anyone help with this?

Hi adkhamllama

What is the function ID here while creating the app coupon and how we can get that?
is it AppDiscountType.functionId ?

Currently an app can only reference its own functions. That is, when invoking discountAutomaticAppCreate, the API Key used must belong to the same app as the function.

In the case of Postman then, be sure you are using an offline access token for the same app.

I have the same problem when i try save a order discount, my app works fine in development store but i dont understand why when install on production store i get “automaticAppDiscount.functionId Function not found”, i tried create others apps and in development store works great but on production I get the same error.

I am installing the app to production by install link.

The SHOPIFY_API_KEY is correct.

My question is: what do i have to do for my app works fine on production store.

@RickyMagana This may also indicate that you are attempting to use a custom app with a non-Plus shop. Functions can only be used in custom/single-shop apps with a Plus subscription.

That has sense, thank you.

How to get the “offline access token”?

Nick, Hi, I am struggling with this also. I am using a custom/single-shop setup, and trying to create a product discount function following the tutorial https://shopify.dev/docs/apps/selling-strategies/discounts/experience/getting-started.

When I move it to the production store, running the GraphiQL query to retrieve the functions in step 4, does not return the function, even though it is installed.

I followed this https://shopify.dev/docs/apps/auth/oauth/getting-started to create an offline token using the client_id from the app listed in the shopify partner site.

Using this access token, I can now run a graphql, which lists out the function correctly, but when I try to add the discountAutomaticAppCreate via graphql using the same access token, it returns ‘function not found’.

The token has write_discounts scope.

Any idea what I’m doing wrong?

Does the store need to be on a PLUS plan for this to work?

“Functions can only be used in custom/single-shop apps with a Plus subscription”

This kind of suggests that they do, but I have other (cart-validation) functions working with a single shop/custom setup…???

1 Like

this details the steps required https://shopify.dev/docs/apps/auth/oauth/getting-started

hello,

mutation {
discountAutomaticAppCreate(automaticAppDiscount:{
startsAt: “2024-09-25”,
title: “Order Discount”,
functionId: “4e215005-26ae-486b-b310-54827cdd4cf7”
}) {
automaticAppDiscount {
discountId
}
userErrors {
code
message
}
}
}
This function works in my development test store and I get an internal server error in the production area. I wonder if the Order Discount Function is available only for Shopify Plus subscribers.
Here is the error I encountered during this mutation operation :
{
“errors”: [
{
“message”: “Internal error. Looks like something went wrong on our end.\nRequest ID: 690f9175-1aaf-4b24-8caf-5c79c7a2ff72-1727308714 (include this in support requests).”,
“extensions”: {
“code”: “INTERNAL_SERVER_ERROR”,
“requestId”: “690f9175-1aaf-4b24-8caf-5c79c7a2ff72-1727308714”
}
}
]
}