#HK6-python-pagination

1 messages ยท Page 1 of 1 (latest)

silver carbon
#

What happens when you try hard-coding the LIMIT variable?

thorny hill
#

good question

#

let me check

#

same thing

#

still get them 10 by 10

#

after the first call
charges = stripe.Charge.list( created= {'gt': start_after_date}, limit=LIMIT, expand=["data.customer", "data.disp...
If I check the length of the result, I get 100 actually (which was the case with the LIMIT variable too)

#

also

#

I get 10 by 10 only in the loop afterwards

#

also

#

the auto_paging_iter, starts necessarily after the first 100 results I get?

#

or does the first call sets a kind of pointer and the auto paging iterates on all the results ?

#

including the first 100

#

?

silver carbon
#

Let me run on my end. That looks right and it should be returning 100 at a time

thorny hill
#

thanks

silver carbon
#

Running your code I was able to get 100 in the first API response

thorny hill
#

I am not using the starting after

#

my variable name is confusing

#

sorry for that

#

I am using the created filter

silver carbon
#

It's all good. It might be worth watching this if you're just getting started on pagination: https://www.youtube.com/watch?v=13StUEc9XrY&t=130s

Learn how to work with lists of Stripe objects using the stripe-node client libraries, including how to take advantage of auto-pagination.

Presenter

Amanda Lee - Technical Solutions Engineer at Stripe

Resources

Official documentation: https://stripe.com/docs/api/pagination
Code: https://github.com/stripe-samples/developer-office-hour...

โ–ถ Play video
thorny hill
#

and start_after is actually a unix timestamp

#

thanks

#

I'll look at this

#

thing is the python example and the node one seems slightly different

#

`import stripe
stripe.api_key = "sk_test_eKSoknCBrKGGTSmZqvaU5QET00e3xqZ0U9"

customers = stripe.Customer.list(limit=3)
for customer in customers.auto_paging_iter():

Do something with customer`

#

and for node where the initial call is in an async for:
const Stripe = require('stripe'); const stripe = Stripe('sk_test_eKSoknCBrKGGTSmZqvaU5QET00e3xqZ0U9'); // In Node 10+: for await (const customer of stripe.customers.list({limit: 3})) { // Do something with customer }

#

looks like in python I would loop on all the results including the one I get in the first call right?

#

otherwise I should do:
`import stripe
stripe.api_key = "sk_test_eKSoknCBrKGGTSmZqvaU5QET00e3xqZ0U9"

customers = stripe.Customer.list(limit=3)

Do something with forst 3 customers

for customer in customers.auto_paging_iter():

Do something with customer`

No?

#

Gotta sleep... past midnight here I'll be back at it tomorrow fresher ๐Ÿ™‚

#

thanks for your help

silver carbon
#

AH apologies for the wait. I'm juggling a few threads simultaneously. Let us know to reopen your thread tomorrow and we can start again ๐Ÿ™‡โ€โ™‚๏ธ

thorny hill
#

no worries

#

I should not be working that late on such things

#

prone to mistakes anyway

cosmic temple
#

@thorny hill I just want to make sure I dropped in here (for your reference in the morning) that the approach in Python will not skip the first 3 Customers. The difference is purely syntax between languages but the behavior is the same

thorny hill
#

Ok thanks

#

so just need to understand why the pagination goes 10 by 10 instead of 100

cosmic temple
#

Default limit is 10