#chooke
1 messages ยท Page 1 of 1 (latest)
hi there, can you share the request id [0]? it'd look like req_xxx
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
req_qKJakUrqA7ewWT
i would expand this parameter instead : https://stripe.com/docs/api/subscriptions/object#subscription_object-items-data-price-product
i tried to do that , but it didnt work ,as i have 2 products ,
app.get("/get-subscription", async (req: Request, res: Response) => {
const { customer } = req.query;
try {
const subscription = await stripe.subscriptions.list({
customer: customer?.toString() || "",
expand: ["items.data.price.product"],
});
console.log(subscription.lastResponse.requestId);
res.status(200).send(subscription);
} catch (err) {
res.status(500).send(getErrorMessage(err));
}
});
what does it didn't work mean? are you getting an error?
sorry , so i get [TypeError: Cannot read property 'data' of undefined]
so this is the subscription id (sub_1MUQbgC68fMI8JtvRNEZs5y8) i have 2 products in it , when i have only 1 , i was able t expand on the items/plan , but after adding a new product , i get null value for plan field
you shouldn't be referring to the plan field
what's the aim here? what specific data are you trying to retrieve? i.e. is it the Price id, or maybe the Product id?
so im trying to get the product from the subscription
i see you return the subscription object in your response
how are you accessing the plan in your frontend? can you share the code for that?
if i expand on items , i cant get even the subscription
const subscriptions = await fetchStripeAccount( `${stripeEndpointUrl}/get-subscription?customer=${customerId}`, accountGetRequestOptions, );
this is how i call the endpoint
to expand the Price for a Subscription, this should be what you expand - data.items.data.price
you can only expand up to 4 levels deep. So if you want more details about the Product (besides just the id) this probably isn't the best solution
the reason why i don't recommend using Plans is that it's considered as deprecated at this point. If you're attempting to access Subscription.plan -> it will be null if you have more than one item on the Subscription
ohh thats why , so what would be the best approach to handle this , can you recommend me a better way to get to the plan details
that's why i mentioned accessing the Price instead
that means i have to do extra api calls to get the product since we can access 4 levels deep only :/
why do you want to get the product? and what details of the product specifically?
so we have an app , that users can subscribe to a plan , in one of the plans users can add extra staff , so that means adding an extra product to the subscription items , what we are trying to do is to display the current subscription and the product details like the name , price
since some subscriptions can have 2 products , and this is why i had that issue with null value, i need a better way to get the subscription and the product details , but only the product that is not for adding extra staff ,
this sounds complicated ๐
what i would do is to save the relevant details to your own DB, and query it directly from your DB. Otherwise, there's no real alternative here, you just have to make an additional API call