Gets the product ID for multiple products

Highlighted
Tourist
20 0 2

I need to create a collection based on a list of product handles, using GrapgQL.

 

I can see how to add a product to a collection using the ID.

 

To be able to add a product to a collection looks like I need the ID, but initially I will only have the handle. Of course I could query the api for the ID, using the handle.  Do I need to do that one by one?  Do I just do an OR in the Graphql query?

 

Is there a clever way to do this?

 

Any direction would be appreciated

 

Thanks

 

Grant

 

0 Likes
Shopify Partner
1054 116 170

Yes, you'll have to chain them. There are nicer queries on nodes() but those will only work for an array of IDs. Why would you have only handles if I may ask? Are they coming from an external system?

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
Tourist
20 0 2

That's right, an external system.  We use an isbn or a work identifier as as our unique key.  We don't store the created product id as there would be way too many and we don't want to be responsible for managing something that we have no control of (or trust of - because it isn't ours)

 

In this case it looks like I will need to query by handle, get id and repeat.  I can make the graphql query simple so as not to cost me too much.  In some cases I may have 100\200 queries to do so there would be a lot to chain.

 

Thanks

 

Grant 

0 Likes