#nanzepanze-api-reporting
1 messages ยท Page 1 of 1 (latest)
hi @vapid oasis I added some more details to my initial message ๐
gotcha, then yes listing BTs once a day and stopping once you reach the most recent BT you accessed last time is the right approach
you can also use webhooks https://stripe.com/docs/webhooks to stay on top of all changes in real time, but there are some BTs that won't trigger any event so you still need the list BT approach as a back up
good point I considered using webhooks and real-time ingestion into the accounting platform without knowing that some events would not trigger. Good thing I decided to keep it simple ๐
you could also look at https://stripe.com/docs/reports/api
Ok so I'm looking at the right Stripe API which is good. I did some dirty testing using curl specifying the created gte and lte to specify the previous 24 hour period. You are suggesting doing the time filtering in a different way?
yeah, if it were me I would simply call https://stripe.com/docs/api/balance_transactions/list and then loop over the list 10 or 100 at a time and stop when you reach the id of the most recent BT you read the day before since it's always ordered by most recent created first
Say you ran your script on Monday and the first BT was txn_DDEEFF. Then today Tuesday you run the script and you get txn_AAA, txn_BBB, txn_CCC, txn_DDD and then txn_DDEEFF => You know you're done, everything after that one you saw yesterday
you can even simplify and pass ending_before: 'txn_DDEEFF' and the pagination will stop automatically
that sounds clever! I'll need to try that. Would use filter on type as you call the balance_transactions/list api or you'd get all transactions and filter on ones that are needed once you've retrieved them?
Honestly I'd get them all and store them all. If you don't, I can tell you in 3 months someone will say "oh can you also store BTs of type Z" and you will have to backfill
hehe you're not wrong ๐
silly question but since I'm just calling one stripe api endpoint is there any advantage to using the full stripe go sdk? do you program in Go?
yeah https://stripe.com/docs/api/pagination/auto will make your life so easy because it's just a few lines of code and you're done. Having to deserialize the JSON is a pain especially for BTs that have complex polymorphic shapes (if you expand other properties per https://stripe.com/docs/expand) and stripe-go handles errors properly, automatic retries, proper header being set, etc.
ok you've sold me! I'll go ahead and use the stripe sdk and translate my testing bash script into proper code. Thank you very much for your quick replies and helpful advice!