Query all products with a given metafield value

Solved
swooders
Tourist
3 0 4

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.  

Visely-Team
Shopify Partner
1836 210 426

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
simonhaenisch
Tourist
5 0 3

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
    }
  }
}
swooders
Tourist
3 0 4

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!

 

Visely-Team
Shopify Partner
1836 210 426

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
raymmondxma
Tourist
5 0 2

use tags

0 Likes
simonhaenisch
Tourist
5 0 3

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
HunterWebs
New Member
1 0 0

This is incredibly sad to hear. I have been thinking about another possible work around. In case those reading are interested.

The idea is to download an entire list (of products for example) from Shopify. Then write some custom code to loop through each one to find a match. So basically download the entire Shopify list to your server for the purpose of finding just one record.

It is incredibly inefficient. Not recommended if you're trying to built a customer facing search feature. But in my case I wish to sync a local data source with Shopify via something other than the Shopify ID. The script itself will be run automatically over night, or manually by a developer. So the lack of efficiency won't really matter in this case.

0 Likes