#ashish_docs
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/1284188499603619850
đ Have more to share? Add more details, code, screenshots, videos, etc. below.
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.
- ashish_api, 1 day ago, 4 messages
- ashish_webhooks, 3 days ago, 18 messages
Hello
Hey!
You can see the Subscription Item object here: https://docs.stripe.com/api/subscription_items/object
So you want to look at the price.product in that case
For each Subscription Item, if you want to know the related Product
The easiest way really is to just retrieve the Subscription and expand items.data.price.product
Then you can get all the info about the Product(s) for the Subscription in one request
If you aren't familiar with expansion take a look at https://stripe.com/docs/expand
Okay so let me try to understand this.
From the customer ID, I go through the list of subscriptions. Then for each subscription, I go through the list of items, then for each of those items i retrieve the subscriptions item and get the ID from there?
Because all I have right now is the customer ID and product ID
I just want to see if the customer has the product ID in their subscription
Then you just List Subscriptions for the Customer and expand data.items.data.price
Oh sorry moving to fast. You don't even need to expand
But yes, a Product is associated to the Price
But wouldn't the Id be different? Because I have multiple pricing for my product (because price IDs start with pr and products with prod
All you need to do is List Subscriptions for the Customer. Then you can get the Product ID from items.data.price.product for each Subscription in your list
Yeah there can be multiple Prices associated to a Product
Oh I see
For the above, since items is a list as well you have to loop through that for each item
But yeah the general idea is that you want items.data[0].price.product
Ah I get it now
And then loop over data
But yeah if you test listing out Subscriptions for a Customer then you should see that all the data you want is returned
You just need to handle it to get the specific Product ID for each item
So I'd do stripe.subscriptions.list(customerID) -> which returns a list of subscriptions the user has
Then I loop through and find the items where items.data.product is equivalent to my product key
Am I getting this right?
Oops yup. I see u have to expand product, so it would be items.price.product
Thanks a lot! That was really helpful, I'll just test something real quickly and see if I have anymore questions
Sounds good!
Hi there, im sorry but i can't seem to get through the first part.
im currently doing ```js
await stripe.subscriptions.list({ customer: data.data[0].CustID }, { expand: ["data.items.price.product"] }); });
and I keep getting an error: `Stripe: Unknown arguments ([object Object]). Did you mean to pass an options object? `
oh i see
Also just to be clear, you are already passing customer within the options object here so you just pass expand alongside that if you wanted to expand
await stripe.subscriptions.list({ customer: data.data[0].CustID,
expand: ["data.items.price.product"] });
Oh, i thought it was always the 2nd argument
Not here for a list request, no.
I see, anyway I have tested my app and everything seems to work! Thanks for the huge help! you can close this thread
Glad to hear it is working!