Solved

Querying based on SKU#s or other method

BLuurr
Shopify Partner
4 0 0

I am trying to query my inventory by SKU in order to receive a batch of data for various items, but the query seems to run into issues where inventory data is managed. I'm comparing a list of SKUs against the entire inventory system, and its slow and doesn't seem to produce good enough results and was wondering if there were any recommendations for how to do go about this process

Accepted Solution (1)

Liam
Shopify Staff
2731 299 769

This is an accepted solution.

Hi BLuurr,

 

Querying inventory can definitely be a bit of a challenge, especially if you're dealing with a large amount of data. Here are a few recommendations that you might find helpful:

  1. Filtering: Instead of querying your entire inventory system, try to narrow down your search criteria as much as possible, to improve both speed and accuracy. For example, you might be able to filter by product type, vendor, or even date of last inventory change.

  2. Pagination: Shopify API allows you to paginate through your inventory items using limit and page parameters in your API call. For instance, you can request inventory items in batches of 250 (the maximum limit), and iterate through pages to get all items.

  3. Throttle your requests: Shopify uses a leaky bucket algorithm for rate limiting API requests. By understanding and following these rate limit rules, you can avoid running into issues where your requests are being rate limited.

  4. Use ShopifyQL: ShopifyQL provides a way to create custom reports and queries against your Shopify data. It might be possible to create a more efficient query using ShopifyQL, depending on what data you're trying to retrieve.

  5. Use GraphQL: If you're comfortable with GraphQL, you might be able to structure a more efficient query using the GraphQL Admin API. With GraphQL, you can specify exactly what data you want to return, which can be more efficient than using RESTful APIs that return all data for a given resource.

  6. Use bulk operations: If you're trying to retrieve a large amount of data, consider using Shopify’s Bulk API. This API is designed to handle large data sets by completing operations asynchronously.

If you continue having performance issues, it may be helpful to reach out to our support team with specific error headers to dive deeper into this. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

View solution in original post

Replies 2 (2)

Liam
Shopify Staff
2731 299 769

This is an accepted solution.

Hi BLuurr,

 

Querying inventory can definitely be a bit of a challenge, especially if you're dealing with a large amount of data. Here are a few recommendations that you might find helpful:

  1. Filtering: Instead of querying your entire inventory system, try to narrow down your search criteria as much as possible, to improve both speed and accuracy. For example, you might be able to filter by product type, vendor, or even date of last inventory change.

  2. Pagination: Shopify API allows you to paginate through your inventory items using limit and page parameters in your API call. For instance, you can request inventory items in batches of 250 (the maximum limit), and iterate through pages to get all items.

  3. Throttle your requests: Shopify uses a leaky bucket algorithm for rate limiting API requests. By understanding and following these rate limit rules, you can avoid running into issues where your requests are being rate limited.

  4. Use ShopifyQL: ShopifyQL provides a way to create custom reports and queries against your Shopify data. It might be possible to create a more efficient query using ShopifyQL, depending on what data you're trying to retrieve.

  5. Use GraphQL: If you're comfortable with GraphQL, you might be able to structure a more efficient query using the GraphQL Admin API. With GraphQL, you can specify exactly what data you want to return, which can be more efficient than using RESTful APIs that return all data for a given resource.

  6. Use bulk operations: If you're trying to retrieve a large amount of data, consider using Shopify’s Bulk API. This API is designed to handle large data sets by completing operations asynchronously.

If you continue having performance issues, it may be helpful to reach out to our support team with specific error headers to dive deeper into this. 

Liam | Developer Advocate @ Shopify 
 - Was my reply helpful? Click Like to let me know! 
 - Was your question answered? Mark it as an Accepted Solution
 - To learn more visit Shopify.dev or the Shopify Web Design and Development Blog

BLuurr
Shopify Partner
4 0 0

Thank you for the response, I did eventually figure out a way to do it the way I needed to. Ultimately the goal was to upload photos based on the sku for a large number of items, and do so without having to paginate through pages of X number of items (because then, afaik, I'd have to create an array of skus, and append until pagination returned a number less than X). Eventually was able to do it by iterating through the inventory by using a lookup for total items (idr exactly what method was used for this) to create a dynamic limit, then iterating over each item until reaching the final item. Within that process I included the logic to fetch photo names from my local storage and match with the handle on shopify. Along with throttling at limit I included a retry method that would occur on failed uploads. I was able to upload around 4000-5000ish photos in one go.