#jake-_list-pagination
1 messages ยท Page 1 of 1 (latest)
๐ Welcome to your new thread!
โฒ๏ธ We'll be here soon! Typically we respond in a few minutes, but sometimes we might take a bit longer if the server is busy or if you have a particularly tricky question.
โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can always start a new thread if you have another question.
๐ This thread will always be available, even after it's closed. You can find it again using Discord's search, or you can save this link: https://discord.com/channels/841573134531821608/1290717668160176189
๐ Have more to share? Add more details, code, screenshots, videos, etc. below.
Hmmm... looking at that request it appears that you are passing the limit integer as a string.
Can you use the exact code I have here and confirm whether or not it work?
params := &stripe.InvoiceListParams{};
params.Limit = stripe.Int64(3)
result := invoice.List(params);
ive just added it but still the same issue
Looking at your request, it looks like we did return 2 items though
hmm, ill have a look see if its my server causing the issue
as its recieving all the results on the frontend
Can you share the exact GO code you are using?
func GetInvoices(c *gin.Context) {
startingafter := c.Query("startingafter")
// Set your secret key. Remember to switch to your live secret key in production.
// See your keys here: https://dashboard.stripe.com/apikeys
stripe.Key = os.Getenv("STRIPE_SECRET_KEY")
var stripeCustomerID models.User
user, exists := c.Get("user")
if !exists {
c.JSON(http.StatusBadRequest, gin.H{"error": "user not found"})
return
}
stripeCustomerID, ok := user.(models.User)
if !ok {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid user type"})
return
}
log.Println(stripeCustomerID.Stripe_Customer_ID)
params := &stripe.InvoiceListParams{}
if startingafter != "" {
params.StartingAfter = stripe.String(startingafter)
}
params.Customer = stripe.String(stripeCustomerID.Stripe_Customer_ID)
params.Limit = stripe.Int64(2)
result := invoice.List(params)
var invoices []stripe.Invoice
for result.Next() {
invoice := result.Invoice() // Get the current invoice
invoices = append(invoices, *invoice)
}
if err := result.Err(); err != nil {
log.Fatalf("Error iterating invoices: %v", err)
}
jsonResult, err := json.MarshalIndent(invoices, "", " ")
if err != nil {
log.Fatalf("Failed to marshal result: %v", err)
}
log.Println(string(jsonResult))
c.JSON(http.StatusOK, json.RawMessage(jsonResult))
}```
Okay so you are triggering our auto-pagination functionality in our SDK with this line
for result.Next()
This means you request 2 Invoices and then fire another API request to get the next two Invoices until you return ALL the invoices
ahhh i see, thank you
Sure thing!
got it sorted now, thank you very much!
Great! Happy to help ๐
also very handy to know about the auto pagination
Yeah, since we limit to 100 results (and it's often better for timeout performance to limit even lower), we needed to implement something that helps auto-paginate results
If, for example, you wanted to perform some scripted process on thousands of Payment Intents
Ahh yeah, that is very useful, have a feeling I will be using it
Cool ๐