Skip to content

Instantly share code, notes, and snippets.

@mrcoles
Last active June 5, 2020 17:06
Show Gist options
  • Save mrcoles/7cc9ec905d979c66d9c22952ab8a485c to your computer and use it in GitHub Desktop.
Save mrcoles/7cc9ec905d979c66d9c22952ab8a485c to your computer and use it in GitHub Desktop.
A look into how Stripe pagination filters and orders results when using pagination

Stripe Pagination Exploration

stripe.Event.list()

  • results: all events
  • order: created desc (most recent to oldest)

stripe.Event.list(ending_before=evt_id)

  • result: events that are newer than evt_id (created at a later time than evt_id)
  • order: created desc
  • if you loop through the results of a regular list events call, this is the cut off point where neither the specified event nor any more events after it are returned

stripe.Event.list(starting_after=evt_id)

  • result: events that are older than evt_id (created at an earlier time than evt_id)
  • order: created desc
  • if you loop through the results of a regular list events call, this is the starting point after which events will be returned
@mrcoles
Copy link
Author

mrcoles commented May 18, 2020

I found that my interpretation of what “starting_after” and “ending_before” mean was the inverse of how it works in the Stripe Api, because I was thinking in terms of when they were created 🤷

Generally objects in Stripe list calls are sorted from newest to oldest, so “ending_before” and “starting_after” are better understood as cut off or starting points (respectively) when going from start to finish in the list of results.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment