Ruby shopify_api gem find all price rules only returns 50 elements

Solved
Highlighted
New Member
2 1 0

I know there are 60 price rules in the store I am working on, but the Ruby ShopifyAPI::PriceRule.all function is only returning 50 price rules.

 

There is very little documentation other than the code for the tests.  There are examples of using pagination with products, but PriceRule.find() doesn't seem to like any params.

 

What does it take to get an accurate, complete list of price rules using the Ruby gem?

0 Likes
Highlighted
New Member
2 1 0

This is an accepted solution.

I have come up with a solution.  There are probably other ways to handle this, but without documentation it's difficult to know.   The solution is to pass a "since_id" parameter, and keep track of the ID of each PR.  From what I've read in some Shopify docs somewhere, if the since_id parameter is provided, it returns results sort ascending by id.

 

prs = {}
last_id = 0 loop do price_rules = ShopifyAPI::PriceRule.all params: { since_id: last_id } break if price_rules.count == 0 price_rules.each { |pr| prs[pr.title] = pr.id; last_id = pr.id } end
0 Likes