#nshah97
1 messages ยท Page 1 of 1 (latest)
Hi ๐
What do you mean by a specific product?
I'd like to use the stripe api to get balance transactions that relate to a certain product e.g. all the balance transactions that resulted from the purchase of a certain product
You would need to list all balance transactions, probably filter by type="charge" and expand the source parameter to get the Charge related to the Balance Transaction. Since you are using Products you must be using Checkout Sessions/Payment Links, Invoices, or Subscriptions. So you will need to work backwards to get to the object that has the relationship to the Product.
Would the filtering by product then have to be done on my end? Or is it possible for me to use the stripe api to return the charge-type balance transactions for a given product
What Stripe API are you using to sell Products?
oh lol, subs
Okay so there is a way to get there but it's a little long
im all for it ๐ช
So you can filter a list of Subscriptions by Price (which is related to Product) : https://stripe.com/docs/api/subscriptions/list#list_subscriptions-price
You then list Invoices for those subscriptions: https://stripe.com/docs/api/invoices/list#list_invoices-subscription
When you list the Invoice you expand the related Charge: https://stripe.com/docs/api/invoices/object#invoice_object-charge
and the Balance transaction for the Charge: https://stripe.com/docs/api/charges/object#charge_object-balance_transaction
So your List API call would be stripe.Invoices.list(subscription="sub_xxxxxx", expand=['charge.balance_transaction'])
Right hm, so i basically want to calculate the total revenue generated for each product over a specified period of time.
Using your suggested solution, and for a given product, would the number of requests id be making to stripe be equal to the number of subscriptions that that product has?
For that you might be better off using our Reporting features: https://stripe.com/docs/reports/api
You can generate and retrieve reports via the API
Hmmm...wait. No I don't see anything related to either Price or Product IDs there either
Essentially i wanna avoid putting stripe.X.list in a loop ๐คช
Yeah I understand that
Is it possible via searching Charges?
Charges have no relation to the Product or Price IDs
charge -> invoice -> lines -> price ?
Yup
so that could be viable option?
It would but it may result in as many API calls
You can always give it a try with a small batch or a single product and review the actual number of API calls and the time it takes