Say I have a plan called 'pro-plan'
, listing all its existing subscribers is quite straightforward
for subscriber in stripe.Subscription.all().auto_paging_iter():
# do something with this subscriber
What I was wondering, is how can figure out users that unsubscribed in a given timeframe?
For example, given start_timestamp
and end_timestamp
how can I find users who have unsubscribed from a specific plan?
Stripe lets you retrieve canceled subscriptions by passing status=canceled
when listing subscriptions (though you need to be on API version 2016-07-06 or more recent to do so).
You'd then need to filter on your end to keep the subscriptions that were canceled during the timeframe you're interested in, using each subscription's canceled_at
attribute.
subscriptions = stripe.Subscription.list(plan='pro-plan', status='canceled')
for subscription in subscriptions.auto_paging_iter():
if start_timestamp <= subscription.canceled_at <= end_timestamp:
# Do something with subscription
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.