Hi, everyone. I need help working with the Shopify APIs.
Basically, I want to generate (Cost of goods sold) COGS values for a store. I'm fetching all the orders for a store within a specific date. Then for each order, iterating through its products and fetching the variant using variant_id and then using the response from that to fetch inventory item AND then finally getting the cost of the item. The result so far has been perfect but my only problem is that it takes hours to finish the process. How can I speed this up? What are my options? Is there an easier way to generate a COGS report?
Because we're creating a custom reporting application that's very specific. Also, because it's paid lol. We also don't have a Shopify Plus or Advanced to use the reporting features from Shopify.
The reporting apps are around $9/month and are completely customizable. You will spend hundreds of hours creating something yourself and end up with 5% of the capabilities.
I've already created a program that gets the COGS and it wasn't that difficult, to be honest, took around 19-20 hours. Regardless, I was hoping for a free solution since our custom app handles around 15 different accounts. If we bought a reporting add 9$ each it would cost us over 1500$ yearly which I think is alot considering we just need the COGS.
I guess it depends how much you value your time. Let's say $50/hour as a conservative number - you have already spent $1000. You have one semi-working report that can't be customized without spending more time/money. Most of the apps have a very generous free plan, which might even get you what you need.
But to answer your original question, I'd suggest looking at web hooks and storing the information that you are using to report on. Building the report each time will never scale.
Your approach has a few flaws, but in general, gets you close. If you wanted a cigar though, you'd have to account for a couple of things. Just getting the orders and line items for a date range is not going to be accurate, as you then have to account for refunds and cancellations. Have fun! Once you cull the crap out of those, you'll know precisely the line items that sold. Now you can get those cost prices via the inventory item. But note, you'll never be penny perfect here either, as you are asking for the cost price NOW, and not THEN, when the item sold. And you know how Shopify has no temporal features for inventory. So the fact is, the cost price now, say 72.45 for an item, may have actually been 68.99 back when the item sold. But you won't know that. So your COGS report is at best, a general exercise. Which, for the most part, is all anyone cares about.
If you wanted to do it faster, you likely could leverage some bulk export if you were lucky, but it seems doubtful as they do not nest deep enough.
Exactly. These and another 100 things that will make this more difficult than you'd expect. The reporting apps have done all the hard work for you.