Finding a Shopify resource using the ruby ShopifyAPI

Took me a while to find this, so here it is for posterity.

In case you want to find an arbitrary Shopify resource using the ShopifyAPI gem, here’s the general syntax:

ShopifyAPI::Order.find(:all, params: { field: term })

As an example, finding a Shopify order by number (as opposed to by ID):

ShopifyAPI::Order.find(:all, params: { name: "#101230" })

Yes, that’s name, not number. Go figure.

However, note that this returns partial matches, so make sure to include all the digits, and filter your results after you get the result. I’ve here reduced the number of possible results by prefixing the number — effectively turning this into a starts with query.

Also, if you use a parameter that doesn’t exist (they’re not very well documented), then it ignores them and returns a much wider set of results.

And, finally, if you want to use the actual resource ID, then you have to pass it as the only parameter. id is not one of the permitted search terms.

Not the best API, IMO, but at least you know where to start.

Leave a Reply

Your email address will not be published. Required fields are marked *