Latest Shopify API 2019-10 Pagination

New Member
2 0 0

Hello,

 

I'm using the latest ruby gem

shopify_api (8.1.0)

In the documentation it has an example:

products = ShopifyAPI::Product.find(:all, params: { limit: 50 })
process_products(products)
while products.next_page?
  products = products.fetch_next_page
  process_products(products)
end

Trying to use it in the Rails Console:

2.6.5 :009 > products = ShopifyAPI::Product.find(:all, params: { limit: 1 })
=> [#<ShopifyAPI::Product:0x00007f843f4a6a30 @attributes={"id"=>2422029025340, "title"=>"Shirt2" etc... }]
2.6.5 :014 > products.next_page?
Traceback (most recent call last):
        1: from (irb):14
NoMethodError (undefined method `next_page?' for #<Shopify::Kaminari::Collection:0x00007f843f4a6aa8>)
Did you mean?  next_page
2.6.5 :015 > products.next_page
 => 2
2.6.5 :016 > products.fetch_next_page
Traceback (most recent call last):
        1: from (irb):16
NoMethodError (undefined method `fetch_next_page' for #<Shopify::Kaminari::Collection:0x00007f843f4a6aa8>)
2.6.5 :017 >

Why i'm getting the following error:

undefined method `fetch_next_page' ?

Please elaborate on this, much appreciated for any advice.

Thank you.

0 Likes
New Member
2 0 0

The issue was caused by gem Kaminari

https://github.com/Shopify/shopify_api/issues/651

After removing it, the cursor based pagination works fine.

0 Likes