Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Limit option not working properly for list_account_invoices #870

Open
sbecka opened this issue Dec 22, 2023 · 1 comment
Open

Limit option not working properly for list_account_invoices #870

sbecka opened this issue Dec 22, 2023 · 1 comment
Labels

Comments

@sbecka
Copy link

sbecka commented Dec 22, 2023

Describe the bug

Hello, I noticed when I set the limit option to 5 or any number for the list_account_invoices method, it gets ignored and returns all account invoices every time. Our Recurly sandbox account has around 40 invoices and all of them get returned each time. I'm not sure if I'm using the correct setup for params or not.

To Reproduce
I used the example code found here and pass the limit option to params: Method: Recurly::Client#list_account_invoices

test_params = { limit: 5 }

invoices = @client.list_account_invoices( account_id: account_id, params: test_params )

invoices.each do |invoice| puts "Invoice: #{invoice.number}" end

Expected behavior

I expected at least 5 account invoices to be returned if the limit is set to 5.

Your Environment

  • Which version of this library are you using? version 4.42.0
  • Which version of ruby are you using? version 3.0.1
@sbecka sbecka added the bug? label Dec 22, 2023
@maleksiuk
Copy link

maleksiuk commented Jun 6, 2024

I've been caught off guard by this too, but it's by design. On all paginated APIs, the Ruby client will automatically iterate through all pages. The limit is only telling it how many records to fetch per page.

To get around this you could do something like:

invoices.each.each_with_index do |invoice, index|
  puts "Invoice: #{invoice.number}"
  break if index >= 4
end

or

invoices.each.first(5).each { |invoice| puts "Invoice: #{invoice.number}" }

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants