Custom filters based on metafield don't work for Storefront API

As of 2022-01 release Shopify supports [custom filters based on metafields](http://%20supports custom filters based on metafields), but support is still severely limited to certain field types. Since announcement was made in a storefront api github repo, my assumption is that it should work in storefront api as well.

I’ve created product metafield with supported type.

Filled it with data and created custom filter based on this metafield.

But when I query API for available filters – I receive all the standard filters you would expect, yeat no custom filters based on product metafields.

# POST here https://**.myshopify.com/api/2022-01/graphql.json
query Facets {
  collection(handle: "all") {
    handle
    products(first: 10) {
      filters {
        id
        label
        type
        values {
          id
          label
          count
          input
        }
      }
    }
  }
}

I’m not sure, why is it not working? Are any extra steps required that I’m not aware of? Or Storefront API support is not included for custom filters?

Hi @skatkov , have you tried the filter query on a smaller collection where you know the first ten products in the collection have a value for the metafield you’re using in the filter you created? If the first ten products didn’t have a metafield value set on the product when querying the filters it would not show up as an available filter. I also just wanted to add that the storefront api currently only supports metafield filtering with metafield types single_line_text_field, number_integer, and number_decimal as of API version 2022-01

@_JCC I’m taking this over from @skatkov on our side. In the query above instead of asking for the first 10 products I have updated the query to ask for the first 250 products. This is all of the products in the collection. Still the result is the same as it was previously.

Hey @PeteCass do you have an x-request-id from the response headers of the StoreFront API request where no filters are being returned? With that I can take a look at our logs and see if there’s anything that jumps out at as a possible cause. The initial release of faceted filtering is online store dependent. Even though you’re using the Storefront API are the products in that collection available on the online store?

@_JCC Thanks, The request ID is 3b9eaf2e-c6f7-42dd-951f-78ea691652ba

The products should be available on the online store

For the community, I just wanted to follow up with a key point about faceted collection filtering with the Storefront API.

Currently, the faceted filtering is tightly coupled to the Shopify online store channel, and only products published to that channel will be available to use in collection filtering. In the case of a headless or custom storefront implementation the products need to be published to the app used for the custom storefront along with the online channel.

Had the same problem, but actually forgot the click it in the online store filtering! Works now!

Hi.

Is there documentation showing an example of filtering via metafield value via the Storefront API?

This page does not mention it.

But this page makes it look / sound like it should be possible.

As do the comments in this thread.

TY!

G

@ndrtek Here are the docs for querying products by metafield value. Although it does not seem to work for me.

https://shopify.dev/api/examples/filter-products#query-products-by-metafield-value

Hey @j-riv I recently added the metafield example to the docs so I’m interested in finding out why it might not be working for you. Have all of the below been verified?

  1. The products are published to the online store channel.

  2. The metafield filter has been added as an available filter under Online store->Navigation->Collection and Search Filters.

  3. The metafield types are any of numeric_decimal,numeric_integer,boolean,single_line_text_field.

  4. You’re using API version 2022-04 or higher.

If it’s a case of some metafield filter types work and others do not please let me know.

2 Likes

Hey @_JCC I had missed step 2, Is that somewhere in the docs? I had never seen the Collection and search filters section under navigation, that’s new to me. Thank you, the query is working as expected.

Hey @j-riv perhaps we can do better with the wording but there’s a link in the requirements section on the filters product page to our online help that identifies setting up the custom filters.

  • You’ve verified that an Online Store 2.0 compatible theme, such as Dawn, is installed by checking if your theme supports filtering. The Online Store 2.0 theme does not need to be the published theme to enable product filtering.
1 Like

@_JCC Hi John, we are testing querying products by either product or variant metafield for a merchant with 95k products in their collection, and unfortunately it’s not working. When the product is early in the collection (e.g., in the first 100) it returns the data. However, we start trying to query for products listed later on and we get an empty result. We have modified our query to do products(first:100000) but to no avail.

The first couple of times we attempted this we got an internal server error (request ID c59c0693-562f-4bc2-b0eb-7534d43d0b27). Afterward we no longer got the error, but it would return empty data for any products that were high in the collection.

Any ideas or workarounds? Thank you.