I want to access a subcsription, to see if the status is active.
I have this:
const subscription = await stripe.subscriptions.retrieve({
email: 'contact@Inderatech.com',
});
res.send(subscription)
however, it doesn't let me do it like this. On the stripe docs, it says to do it like this:
const subscription = await stripe.subscriptions.retrieve(
'sub_icsb2'
);
but i won't have the subscription id unless i grab it using the customer email. So is this possible?
The API only supports retrieving an object by their id. So when you want to retrieve a Subscription you need its identifier, the sub_123.
It is not possible to retrieve a Subscription by another property today and it applies to all APIs. There are List APIs that you can use to filter specific objects. For example when you list subscriptions you can filter them for a specific Price via the price parameter.
Today, the subscription doesn't have an "email" property so there isn't a way to list subscriptions for a specific email. Usually what you want is to first find the customer(s) that have a specific email address via the email parameter and then you can list subscriptions for that specific customer via the customer parameter.