FunctionID In DiscountAutomaticAppCreate

Topic summary

Issue: discountAutomaticAppCreate (GraphQL) reports “function not found”; clarification needed on what functionId is and where to obtain it.

Key points:

  • functionId refers to the ID of the deployed Shopify Function used by the app discount.
  • After coding the Function, you must deploy the app to the store. Deployment generates and writes the Function’s ID into the app’s .env file automatically.
  • You then pass that functionId to discountAutomaticAppCreate in the mutation variables. The startsAt field is required; endsAt can be null.
  • An environment variable (e.g., process.env.SHOPIFY_CQ_PRODUCT_DISCOUNT_ID) can be used to reference the generated ID in code.

Artifacts shared:

  • A code snippet demonstrating the discountAutomaticAppCreate mutation and required fields.
  • An image indicating the .env setup.

Outcome: Confirmed that the ID is auto-populated in .env upon deployment; the participant located it. Status: resolved.

Summarized with AI on January 1. AI used: gpt-5.

Hello,

I’m using graphQL with discountAutomaticAppCreate query but it keeps saying that my function is not found.

What is the functionId and where do I find it?

When you are done with coding of function you have to deploy the app on to your store. Once you have deployed it. In you .env file the app will create a function id of that Shopify Function and then you can use discountAutomaticAppCreate make the mutation the file should be like the below image

`#graphql
        mutation discountAutomaticAppCreate($automaticAppDiscount: DiscountAutomaticAppInput!) {
          discountAutomaticAppCreate(automaticAppDiscount: $automaticAppDiscount) {
            userErrors {
              field
              message
            }
            automaticAppDiscount {
              discountId
              title
              startsAt
              endsAt
              status
              appDiscountType {
                appKey
                functionId
              }
            }
          }
        }`,
        {
            variables: {
                automaticAppDiscount: {
                    title: discount_title,
                    functionId: "you function id goes here",
                    startsAt: enter a starting date it is compulsory
                    endsAt: null,
                }
            },
        },
    );
1 Like

Does the function id automatically be added on the .env file ? or I will manually add it based on the shopify partners dashboard ?

When You deploy the app after creating the discount function the app automatically creates a discount ID then you can use that by writing

process.env.SHOPIFY_CQ_PRODUCT_DISCOUNT_ID
1 Like

Found it. Thank you so much.