#shehzadnizamani_api

1 messages ¡ Page 1 of 1 (latest)

thorny rootBOT
#

👋 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/1331184620510777354

📝 Have more to share? Add more details, code, screenshots, videos, etc. below.

astral folio
bitter vessel
#

Thank you, let me try this out

#

Actually, this is not clear to me. So you are saying that expandable fields can be gotten on stripe.charges.retrieve but not on stripe.customers.retrieve?
My usecase is this, I need to get customer by stripe id and get that customer's active subscription. Is there an easy way to do this that Stripe recommends?

astral folio
#

No, they can be expanding in any API call

bitter vessel
#

Sorry nevermind my previous message, I was able to get expanded field using:
const customer = await stripe.customers.retrieve( stripeCustId, { expand: ['subscriptions'], } );
Please let me know if this code is correct? And a follow-up question:
stripe.customers.retrieve() return type is:
Stripe.Response<Stripe.Customer | Stripe.DeletedCustomer>
Is there an easy way to get Stripe.Customer instead of Stripe.Response<Stripe.Customer | Stripe.DeletedCustomer>

astral folio
#
const customer = await stripe.customers.retrieve(stripeCustId, {
  expand: ['subscriptions']
});

Will work

bitter vessel
#

Yes I figured this out, thanks. Please let me know your answer to my follow-up question

astral folio
#

Is there an easy way to get Stripe.Customer instead of Stripe.Response<Stripe.Customer | Stripe.DeletedCustomer>
Don't understand what you mean

bitter vessel
#

I mean that when I make this API call:
const customer = await stripe.customers.retrieve( stripeCustId, { expand: ['subscriptions'], } );
And then I do this customer.subscriptions typescript complains that:
Property 'subscriptions' does not exist on type 'Response<Customer | DeletedCustomer>'.
How can I tell typescript that return type of stripe.customers.retrieve is Stripe.Customer so that this code works:
customer.subscriptions
Please let me know if this makes it clear?

astral folio
bitter vessel
#

Ok thanks. That's not ideal, but it will work. Those are all my questions