Sorting the Product API response

Highlighted
Shopify Partner
3 0 0

I need to be able to list Products in ascending updated_at order (= product with oldest updated_at first). If I pass in the undocumented "order" parameter and set it to "updated_at", I get the following error response: 

{"errors":{"Attempt to order records by unknown orders updated_at, expected [:total, :title, :created_at, :updated_at]":"Required parameter missing or invalid"}}

Changing to "order=:updated_at" doesn't help (:updated_at is a Ruby Symbol and I can only pass in a String).

It is critical to sort the result, otherwise my cached state will get out of sync with Shopify, resulting in confusion & headaches.

I've read e.g. https://ecommerce.shopify.com/c/shopify-apis-and-technology/t/can-the-returned-results-for-shopify-o... but that doesn't actually work. 

What can we do to get this to work? Thanks!

0 Likes
Highlighted
Shopify Partner
3 0 0

Hi Shayne,

This is a big issue when dealing with stores with large catalogs - the result set needs to be sorted on the Shopify side for incremental processing (e.g. grab 100 at a time, with resume-capability). 

When the result set is sorted by Shopify, then it's super-easy to bite off any catalog a chunk at a time: request 100 items, mirror those, if you're for whatever reason interrupted in the middle doesn't matter since the most recent item in our mirror database is always older than anything we still need to fetch, then rinse and repeat. One API call per chunk, no throttling issues, if my code has issues or my machine goes down, no worries at all.  

Not being able to sort on the Shopify side means I have to fetch the entire catalog, need to throttle those calls (which will now potentally take a lot longer to execute and tie up the mirroring code with a lot of idle waiting), need to store all the results in memory, and then sort them. 

This is inefficient, error prone, slow, and adds unnecessary complexity to what should be a simple process. 

Please add whitelisting of the "order"parameter so that we can pass in "updated_at" as a value to have it sorted by that column. 

And don't let any sandbagging engineers give you any crap about it being hard, I've worked with Rails extensively, this is a five minute job, 1 hour if you include testing and tying a bow around it ;)

 

 

0 Likes
Highlighted
New Member
3 0 0

If you are working with NodeJs, you could use the Shopify Api Node Library there is a method to sort products in a collection:

 

shopify.smartCollection.order(collection.id, {products: your_sorted_ids_of_products});

 

Note: The sort_order of your collections must be set to Manual in order to work.

 

0 Likes