Cannot update function

When I send the discountCodeAppUpdate mutation to edit the discount I get the following error back.
https://shopify.dev/api/admin-graphql/2022-07/mutations/discountCodeAppUpdate


code: “INVALID”
field: (2) [‘codeAppDiscount’, ‘functionId’]
message: “Not allowed to update the code app discount.”

How do I allow the discount to be renewed?

Hi @Hirano_00 ! In your update, are you attempting to change the Function ID of the discount?

Does not change the function ID of the discount.I am sending the following GraphQL mutation for updates.

/web/frontend/components/VolumeForm.jsx

await authenticatedFetch("/api/discounts/update-code", {
    method: "POST",
  headers: { "Content-Type": "application/json" },
  body: JSON.stringify({
      data: {
          ...discount,
        title: form.discountTitle,
          code: form.discountCode,
        metafields:[{id: volume.metafieldId}] 
        },
       id: volume.id
    })
})

web/middleware/discount-code-api.js

const UPDATE_CODE_MUTATION = `
  mutation UpdateCodeDiscount($discount: DiscountCodeAppInput!, $id: ID!) {
    discount: discountCodeAppUpdate(
      codeAppDiscount: $discount,
      id: $id
    ) {
      userErrors {
        code
        message
        field
      }
    }
  }
`;

All source code can be found here.
https://github.com/maneko00/discount-node-test

If you could give me some advice, I would be very grateful!

Sorry for repeating myself. I still haven’t figured out why I can’t update the discount. Shopify function is still the same one I created in step 4 of the tutorial. Do I need to change the extensions/volume folder when updating the discount?

https://shopify.dev/apps/discounts/create

Hey @Hirano_00 – Can you try leaving off the functionId parameter entirely when invoking the update mutation?

I was going to try this myself and PR your repo but you appear to be missing the web/index.js file for some reason in your app.

-Nick

1 Like

I could update the discount by removing the functionId parameter! Thank you.