#jake-_list-pagination

1 messages ยท Page 1 of 1 (latest)

shadow mortarBOT
#

๐Ÿ‘‹ 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.

restive stag
#

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);
candid hedge
#

ive just added it but still the same issue

restive stag
#

Looking at your request, it looks like we did return 2 items though

candid hedge
#

hmm, ill have a look see if its my server causing the issue

#

as its recieving all the results on the frontend

restive stag
#

Can you share the exact GO code you are using?

candid hedge
#
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))
}```
restive stag
#

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

candid hedge
#

ahhh i see, thank you

restive stag
#

Sure thing!

candid hedge
#

got it sorted now, thank you very much!

restive stag
#

Great! Happy to help ๐Ÿ™‚

candid hedge
#

also very handy to know about the auto pagination

restive stag
#

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

candid hedge
#

Ahh yeah, that is very useful, have a feeling I will be using it

restive stag
#

Cool ๐Ÿ˜Ž