d
Topic
Kolby Member
Posts:
10
11 days ago

Making thousands of API calls, taking forever

I'm building a Shopify app with Ruby on Rails, using the shopify_app gem. Currently, I'm looping through every single order in the past 30 days and then looping through each product inside of that order, in order to get data such as inventory count etc.. The goal is to get the amount of each product sold in the past 30 days along with their inventory count. I have a shop with over 5,000 orders in the past 30 days so the process takes forever. I have it running as a background job.

Is there a better way to do this? It's going to take hours the way I'm currently doing it.

i
Replies
Josh Wheeler Shopify Employee
Posts:
485
4 days ago

Hey Kolby, 

In all honesty that just sounds like a lot of data and something that will take time - I can't really think of any (simple) other way to do it faster.

Using GraphQL instead of REST may be able to page through it a bit more quickly if you're familiar with it though, aside from that my only other thought would be that shops using our Advanced subscription or higher would have access to the Analytics API. You could likely use that to fall back on our sales data that we already have available instead of having to count things up on your own.