#shehzadnizamani_api
1 messages ¡ Page 1 of 1 (latest)
đ 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.
It's an expandable field you need to specify that in your request: https://docs.stripe.com/api/expanding_objects
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
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?
No, they can be expanding in any API call
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>
const customer = await stripe.customers.retrieve(stripeCustId, {
expand: ['subscriptions']
});
Will work
Yes I figured this out, thanks. Please let me know your answer to my follow-up question
Is there an easy way to get Stripe.Customer instead of Stripe.Response<Stripe.Customer | Stripe.DeletedCustomer>
Don't understand what you mean
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?
You'd need to cast it: https://github.com/stripe/stripe-node?tab=readme-ov-file#using-expand-with-typescript
Ok thanks. That's not ideal, but it will work. Those are all my questions