Query all products with a given metafield value

Solved
Highlighted
Tourist
3 0 1

I am working a shopify app where I want to know the "status" of each product, which is either "complete" or "needing review". My app needs to pull all "needing review" products into the interface and show them in a paginated ResourceList. 

 

In order to pull all products with the status "needing review", I believe I two options:

1. Query from Shopify all products with the status "needing review"

2. Record in my own database the list of product ids that need review, and filter my queried products by those ids. 

 

I've been trying option (2.) however its extremely messy to simultaneously support pagination and search while also filtering queried products with a list of ids. For example, I will read 50 products for a page, but then only 35 will have the correct status, so then I end up with each of my pages having a different number of products. 

 

Option (1) would be  much easier if I am able to query Shopify products by what status I have given the product. However it seems like the only place in a product I can add custom information is in the metafields. From looking at this post https://community.shopify.com/c/Technical-Q-A/Querying-productvariants-by-metafields-in-GraphQL/m-p/... and the QueryRoot documentation (https://help.shopify.com/en/api/graphql-admin-api/reference/queryroot) it doesn't seem like its possible to query by metafield value. 

 

Basically, I'm really confused about how I can query products by a custom field.  

1 Like
Highlighted
Shopify Partner
1718 209 348

This is an accepted solution.

Unfortunately, there is no way to query products by metafield value or any other "custom" field value.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
1 Like
Highlighted
New Member
2 0 1

Need this as well... one of the main reasons we want to use private meta-fields for our app would be so that we can retrieve a list of products that we have tagged. Having to sync that with another DB just because the meta fields aren't queryable is somewhat cumbersome.

 

Is adding a query option for (private) meta-fields something that would be considered to be added to the API? It would already be sufficient if it's as simple as being able to query for a key name.

 

Example of what it could look like to query all products that have a private meta-field with key "status":

 

query getProductsWithMetaField {
  products(first: 5, query: "private_meta_field:status") {
    edges {
      cursor
    }
  }
}
1 Like
Highlighted
Tourist
3 0 1

Thank you so much for your response! What is the recommended/standard way to add information about each product in a queryable way? I imagine it's fairly common for apps to need to query products by some information that they added to each product. Is the only solution to copy everything into a separate database to made the data queryable? 

 

If the solution is a separate database, how do we manage syncing the database to ensure its up to date with all the merchant's products? Will web hooks capture all updates to the products?

 

Thank you!

 

0 Likes
Highlighted
Shopify Partner
1718 209 348

Unfortunately, yes. As to the ways to ensure all updates are caught, you'd use webhooks + scheduled Products REST API with updated_at_min filter to do reconciliation on possible missed updates.

Sergiu Svinarciuc | CTO @ visely.io
- Was my reply helpful? Click Like to let me know!
- Was your question answered? Mark it as an Accepted Solution!
- To learn more about the awesome stuff we do head over to visely.io or our blog
0 Likes
Highlighted
Tourist
5 0 2

use tags

0 Likes
Highlighted
New Member
2 0 1

use tags

Unfortunately tags are public-facing, e. g. the shop customer will be able to filter the catalog by tags. Not really a good place to store app-specific data.

0 Likes