FunctionID In DiscountAutomaticAppCreate

Thegraske
Shopify Partner
7 0 0

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?

Replies 4 (4)

Hamza_Hussain
Shopify Partner
23 1 3

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

 

Hamza_Hussain_0-1710328963977.png

        `#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,
                }
            },
        },
    );
Honey_G_Hamza
tyuzu
Shopify Partner
9 0 0

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

Hamza_Hussain
Shopify Partner
23 1 3

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
Honey_G_Hamza
tyuzu
Shopify Partner
9 0 0

Found it. Thank you so much.