Get Transactions In Batches ShopifyAPI

- 1 answer

Is it possible to retrieve Transactions in batches? I currently retrieve orders using:

ShopifyAPI::Order.find(:all, params: {ids: order_ids.join(',')})

Where order_ids contains up to 50 order_ids. However, if I try to get the transactions attached to the other, it makes one get request per transaction, looking into the ShopifyAPI code under the hood it's doing this:

Transaction.find(:all, :params => { :order_id => id })

I tried loading it in batches using:

Transaction.find(:all, :params => { :order_ids => order_ids.join(',') })

However, I get an error from the API saying that order_id is not defined. Order_id only gets the transactions for one order, any way to look this up in batches?

For context, I'm trying to write some reporting/analytics on our own side around the transactions, so looking up the transaction on an per-order basis leads to making too many requests and getting an error code 429. I can create a rake task that does this slowly and schedule it through cron, but I thought I'd ask if it's possible to grab them in batches since having a job is less than ideal.



You should not be afraid of rate limiting. You do have to provide one order per call to Transaction end point. Since your analytics are not real-time, just set yourself up with a task that downloads within limits.

For a simple example of how to do this, examine the Shopify open-source Ruby gem for the Theme tool. It has a downloader for theme assets that clearly runs into this limit too. And they built a nice way around that.

In its simplest form, you get a 429 response to your request. So don't quit there. Just wait till you have more calls available. You can dream up many options for that. In the end, you get ALL the data you need, for a few more lines of code.

One does not solve problems with the Batch idea as you put forth here, instead, one adjusts their code to suit the rules of the system. There are many explanations as to why batch processing is not in place for resources like this.