#eple0030_api

1 messages ยท Page 1 of 1 (latest)

chrome ospreyBOT
mellow gardenBOT
#

Below are links to other discussions we've had with you in the past week in case you want to review that information. If your question is related to one of these previous discussions, please provide a comprehensive summary of the current state and what you need help with now. We help many users simultaneously, so a summary allows us to resolve your issue as soon as possible.

chrome ospreyBOT
#

๐Ÿ‘‹ Welcome to your new thread!

โฒ๏ธ We'll be here soon! We typically respond in a few minutes, but in some cases we might need a bit more time (e.g., server's busy, you've got a complex question, etc.).

โฑ๏ธ We close idle threads, which makes them read-only. Once a thread is closed it won't be reopened, but you can 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/1258089462223601794

๐Ÿ“ Have more to share? Add details, code, screenshots, videos, etc. below.

soft sphinx
#

Hi)

timber finch
#

Hello! You can't retrieve that information on a Checkout Session without using expansion. Why can't you use expansion for this?

soft sphinx
#

I guess i didnt use the right syntax

timber finch
#

Actually, I was just looking at this, and you can't expand total_details.breakdown.discounts.discount.promotion_code on a Checkout Session because it's more than four levels deep. You would need to retrieve that Promotion Code using a separate API request.

soft sphinx
#

oh.

#

Do you know which request ? When a promotion code has been used during a checkout session, I would like to get the promotion code ID or name, and the discount related amont

timber finch
#

The other details you want should already be on the Checkout Session under total_details.breakdown in various properties.

soft sphinx
#

but you said it was more than 4 levels deep ?

timber finch
#

You wouldn't use expansion. You get the Checkout Session without expansion, you get the Promotion Code ID from it, and retrieve the full Promotion Code ID in a separate API request.

#

Oh, wait, you do need to expand total_details.breakdown

#

I forgot that's not included by default.

#

So get the Checkout Session with total_details.breakdown expanded (which is only two levels deep), then you'll have the Promotion Code ID in there, which you can use to fetch the full Promotion Code object separately if needed.

#

Sorry about the confusion. I've flagged this internally (the five levels deep expansion issue) so we can hopefully improve this in the future.

soft sphinx
#

thanks for the flag

timber finch
#

Yes, I think that should work. Are you seeing what you expect in that response?

#

If not, you might need to URL encode the square brackets, maybe? I'm not familiar with Bubble or how it works with query parameters in URLs.

soft sphinx
#

thanks, seems i could get everything!

#

Can i ask you another question ?

#

what is the easiest way to retrieve a monthy revenue (MRR), like the graph in the stripe home page, for all the clients and also with a breakdown by client

timber finch
soft sphinx
#

sorry, i try to get the data through the stripe API to be able to have a similar graph

timber finch
#

The only way to get it through the API would be to ingest all of the transactions and calculate it on your end. Or to use the API to fetch a report, if one exists for that.

soft sphinx
#

which endpoint would you suggest ?

timber finch
#

It depends on your integration and exactly what you want to base your calculations on. Maybe invoice.paid? Probably others if you also want to take into account things like refunds and disputes.

soft sphinx
#

yes, client payment - discount to keep simple

chrome ospreyBOT
timber finch
#

If you're using Stripe Subscriptions I think invoice.paid will have what you need to get started.

soft sphinx
#

And to add a breakdown per month ? (per month all activity, and per month per client) ?

little mulch
#

Hi there ๐Ÿ‘‹ taking over, as my colleague needs to step away

Can you elaborate on what "breakdown per month" and "per month activity" and "per month per client" mean? These are really vague terms.

soft sphinx
#

thanks ! my use case is the following : Retrieve clients data (eg. saas) from stripe, using Oauth and through stripe api, and display

  • their monthly revenue (on a graph)
  • the monthly payment from their clients

I am wondering which endpoints would be the easiest to do that

little mulch
#

Are you not going to user webhooks to get that data in real-time? Sounds like you might be looking for a bulk fetch instead, but wanted to clarify

soft sphinx
#

I would need to retrieve data and update them once a month only, to make it more simple than real time, not sure i need webhooks for that

little mulch
#

Yeah, that sounds like a batch request. There are a couple ways you can go about that. You can either:

(a) run/retrieve one of the reports via the Reports API https://docs.stripe.com/reports/api, or
(b) get all the raw data from one of the various List All API endpoints and iterate through it to grab what you want, for example the Balance Transactions API https://docs.stripe.com/api/balance_transactions/list

soft sphinx
#

and for the Balance Transactions API for exemple : how to get month by month data ? Sort by "available on" or "created"?

little mulch
#

Yup exactly

soft sphinx
#

and for the customer, is there a way to get this info on the balance transactions or need to use another report ?

little mulch
#

I don't understand the question. Are you asking how to associate a Balance Transaction with a Customer?

chrome ospreyBOT
soft sphinx
#

yes, or just retrieve revenue by customer and by month

hazy harbor
little mulch
#

You would need to list all Payment Intents by Customer and cache the ID from the latest_charge, which represents the Charge object associated with the Payment Intent:

Then loop through those Charge object IDs and make requests to the List All Balance Transactions endpoint, passing each Charge ID into the source parameter: https://docs.stripe.com/api/balance_transactions/list#balance_transaction_list-source

soft sphinx
#

Ok, so it is the easiest way you suggest ?

#

Thanks!, I will have a look play with the date

little mulch
# soft sphinx Ok, so it is the easiest way you suggest ?

The easiest way would be to use the Reports API, but this way works too. You could also just use the List All Payment Intents API to get just the Payment Intents and inspect them to see if they were paid or not. A lot of different ways to accomplish this, so I would recommend reading through the API reference and looking for optimizations for each of the batch data requests you want to make