#ashish_docs

1 messages ¡ Page 1 of 1 (latest)

urban lintelBOT
#

👋 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.

deft harness
#

Hello

hidden mist
#

Hey!

deft harness
#

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

hidden mist
#

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

deft harness
#

What data do you want here?

#

Okay you just want the Product ID?

hidden mist
#

I just want to see if the customer has the product ID in their subscription

deft harness
#

Then you just List Subscriptions for the Customer and expand data.items.data.price

hidden mist
#

Oh

#

price?

deft harness
#

Oh sorry moving to fast. You don't even need to expand

#

But yes, a Product is associated to the Price

hidden mist
#

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

deft harness
#

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

hidden mist
#

Oh I see

deft harness
#

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

hidden mist
#

Ah I get it now

deft harness
#

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

hidden mist
#

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?

deft harness
#

items.data.price.product

#

But yep

hidden mist
#

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

deft harness
#

Sounds good!

hidden mist
#

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? `
deft harness
#

Sorry I confused you with the expansion

#

You don't need to expand anything here

hidden mist
#

oh i see

deft harness
#

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"] });
hidden mist
#

Oh, i thought it was always the 2nd argument

deft harness
#

Not here for a list request, no.

hidden mist
deft harness
#

Glad to hear it is working!