#snow-invoice-pagination

1 messages · Page 1 of 1 (latest)

unborn streamBOT
pale carbon
#

snow-invoice-pagination

#

@alpine oxide https://stripe.com/docs/api/pagination explains this in details. You can pass a limit: 20 to only get 20 results and look at the has_more property to see if there are more results or not.

alpine oxide
#

The property has_more only works in one way, right ?

pale carbon
#

I'm confused by the "one way" wording. But yes you ask the API "hey give me 20 Invoices" and it gives you the 20 most recent and has_more: true tells you there's more after
When you paginate, based on whether you use starting_after or ending_before controls which ways you paginate and the meaning of has_more

alpine oxide
#

Sorry for the confusion, but yes that's what I thought. So, if it give me the 20 first invoices, and has_more is true, by default this means that there are more invoices after the last invoice. Is there any way to get has_more data before the first invoice with the same request ? Tell me if it's still not clear

pale carbon
#

If you pass ending_before: 'in_1234' it will tell you "there are more Invoices before that page I just retrieved so yes

alpine oxide
#

But if I doesn't pass ending_before: 'in_1234', I will get "there is more invoices or not, after that page. So, I can't know with the same request if there are more invoices before and after?

pale carbon
#

there wouldn't be any "before" since you'd get the 20 more recent Invoices already

alpine oxide
#

Okay, I'll explain the objective, I think you'll understand better.
I want 2 buttons

  • Previous: Go to previous page
  • Next": Go to next page

These two buttons must be disabled if there is no more data, respectively, before and after the current page.
I'd really like to do this in a single request if possible.

pale carbon
#

sure, you just cache this yourself really

#

If you render page 7, you got there a certain way, usually by doing next from page 1 to 7, so you know there are invoices before. If you go back to page 6 then you're going to use ending_before: in_123 where that is the most recent Invoice id on page 7. So on page 6, you know has_more: true now means "there's a page before page 6" and you remember there's a page after as you came from page 7

#

no way to know both ways unless you cache some of it on your end which is kind of logical

alpine oxide
#

Ok, that's what I wanted to know thank you!

pale carbon
#

sure thing!

alpine oxide
#

Have a nice day/evening