Shopify Function to read the applied discount codes, if a string is found set shiping to $0.00

I have created an extension only app that has a shipping discount extension.

My input query:

query RunInput {
  cart {
    discountCodes {
      code
    }
  }
}

Based on the GraphQL explorer found here: shopify.dev/graphiql/storefront-graphiql

but I get the error:

“Error 0: Cannot query field “discountCodes” on type “Cart””

I am replacing a Shopify script that iterates through the applied discounts, looking for a specific substring in those discount names. If the substring is found, it sets the shipping cost to $0.00.

If discountCodes is not queryable why do I find it in the explorer? If what is found in the linked explorer is not valid, where am I to find the shape that can be queried in a clear and concise format like that GraphQL explorer?

If there is no such resource, please help me produce an input query that will give me the applied discount codes, that I can iterate looking for target strings, that if found will allow me to apply a 100% shipping discount.

Sincerely stumped,

Confused Query Quester

Hi,

I don’t think Discount Codes is available in the set of input parameters in Shopify as of now.

Check available input parameters here: https://shopify.dev/docs/api/functions/reference/shipping-discounts/graphql/input

If it is not possible to get the discounts as input to a function how can I get the list of accepted discount codes and then add a shipping discount based on the strings found in that list?

If the discounts cannot be added to an input query, is there any to get the discount codes in an extension only Shopify App?

I have been able to get the codes via a remix app, but in the remix app I cannot change the cart to add a discount for shipping.

Can this be accomplished using the webhooks that are defined in a remix app?

If this is just not possible it would be very helpful if someone from Shopify could let me know as I have been beating my head against this for weeks now. If it is not possible, I need to let my client know so we can look for alternative options ASAP.

Despondently Yours,

:broken_heart: :chart_decreasing: :woman_technologist:

Discount-Despairing Developer

Looking for this same thing, did you ever find an answer @KellyEldritch ?