How to get product tags on my Function?

Topic summary

A developer is building a Shopify Function using the Discounts API that needs to apply discounts based on product tags (e.g., excluding products tagged not-eligible-for-discount).

Core Challenge:

  • Cannot use hasAnyTag or hasTags in the input.graphql file because users need to specify tags dynamically via a text field in the app configuration
  • Shopify Functions don’t support network requests or async operations, preventing GraphQL queries within the function itself to fetch product tags

Proposed Solution:

  • Use variables in the input.graphql file
  • Store the list of tags as a metafield and combine it with the input query
  • Reference: Shopify’s documentation on variable queries for Functions input/output

Current Status:
The original poster confirmed this approach meets their needs. Multiple other users have since asked for similar solutions, with one community member sharing a related discussion thread about making hasTags dynamic in discount functions.

Summarized with AI on November 5. AI used: claude-sonnet-4-5-20250929.

I have a Shopify Function using Discounts API which will apply discounts depending on the product tags, e.g. if a product has a not-eligible-for-discount tag my FunctionResult will not apply discount to this.

My input.graphql is as follows

query Input {
  cart {
    lines {
      quantity
      merchandise {
        __typename
        ...on ProductVariant {
          id
          product {
            id
          }
        }
      }
    }
  }
  ...
}

On my Function I was planning to get product.id (defined in my input.graphql) and then perform a graphql request to get the product tags given I can’t grab these from the Input query. The problem is that as the doc says it’s not possible to perform network requests or async operations. Is there any other approach I could follow to accomplish this? I can’t use hasAnyTag or hasTags to accomplish this because in this case I would have to provide the tags in the input.graphql file and instead I need to make the user able to provide the tags they want in a text field.

You can add variables to your input.graphql file. In my automatic discount app, I put together a list of tags, and then add these as a metafield which is combined with my input query.

Documentation: https://shopify.dev/docs/apps/functions/input-output/variables-queries

2 Likes

That’s exactly what I need, thanks @tobebuilds

Hi Maikenegreiros, Did you got the solution how to fetch product tags ? please let me know as well

Hi,

I haven’t found a solution yet, but any workaround is appreciated. I also need to access product tags in a function.

Thanks!

Perhaps this could help:

https://community.shopify.com/c/technical-q-a/how-to-make-the-hastags-part-of-a-discount-function-dynamic-in-a/m-p/2765385/highlight/true#M174824