Skip to content

Conversation

@mbroshi-stripe
Copy link
Contributor

@mbroshi-stripe mbroshi-stripe commented Oct 14, 2025

Why?

This PR address issues like #2168 where users want to manually paginate instead of auto-paginate after a List call using stripe.Client. Although there are possible workarounds with the current design, they are quite hacky (e.g. requesting an additional item from the API to determine if HasMore is true).

After much internal debate, we decided the best path forward to support both the manual and automatic pagination use cases is to introduce a breaking change where List returns a struct instead of a func. You can access the underlying data on the struct with Data() and Meta() methods, or call .All(ctx) to get back to the auto-pagination behavior. This is in line with how our other language SDKs handle List.

So, automated pagination will look like this:

for c, err := range sc.V1Customers.List(ctx, nil).All(ctx) {
	// handle err
	// do something
}

and manual pagination will look like:

list := sc.V1Customers.List(ctx, nil)
if list.Err() {
	// handle err
}
doSomething(list.Data(), list.Meta())

What?

  • ⚠️ List and Search methods using stripe.Client now return a struct instead of Seq2.
  • All of the logical changes are in iter.go and search_iter.go, where the new types and methods are introduced, and internal pagination logic depends on page() instead of next().
  • Exports the type v1List --> V1List with a v1Page struct that represents the response from the API.
  • Deprecates the NewV2List function and Fetch type which were really meant to be used only internally, and not exported.

Changelog

  • ⚠️ List and Search methods using stripe.Client now return a struct instead of Seq2. This is a backwards incompatible change, and you will need to add an additional call to .All(ctx) in your for loop. E.g.
-for c, err := range sc.V1Customers.List(ctx, nil) {
+for c, err := range sc.V1Customers.List(ctx, nil).All(ctx) {
	// handle err
	// do something
}

For manual pagination use cases, you can access the API call's error by calling list.Err(), a page's data using list.Data(), and its metadata by calling list.Meta().

@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/RUN_DEVSDK-1972/add-list-with-page branch from accde7d to 8554d74 Compare October 19, 2025 01:15
@mbroshi-stripe mbroshi-stripe marked this pull request as ready for review October 20, 2025 19:16
@mbroshi-stripe mbroshi-stripe requested a review from a team as a code owner October 20, 2025 19:16
@mbroshi-stripe mbroshi-stripe requested review from prathmesh-stripe and removed request for a team October 20, 2025 19:16
@mbroshi-stripe mbroshi-stripe changed the title Add List/SearchWithPage methods to stripe.Client services Update List and Search methods with stripe.Client to return a struct Oct 20, 2025
@mbroshi-stripe mbroshi-stripe force-pushed the mbroshi/RUN_DEVSDK-1972/add-list-with-page branch from 95021ce to 5e13068 Compare October 20, 2025 21:21
@prathmesh-stripe
Copy link
Contributor

Is it possible to do a diff like statement in the changelog: That would be easier to understand for people going through the changelog to understand the required change.

-for c, err := range sc.V1Customers.List(ctx, nil) {
+for c, err := range sc.V1Customers.List(ctx, nil).All(ctx) {

@mbroshi-stripe mbroshi-stripe changed the title Update List and Search methods with stripe.Client to return a struct [Breaking] Update List and Search methods with stripe.Client to return a struct Oct 27, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants