Stripe - get subscription for specific email

Viewed 149

I have customer email. How to check does customer have valid subscription? I'm using cUrl. Thank you.

2 Answers

Stripe allows expand responses. Fortunately subscriptions property of customer object is expandable. Thus, you can reduce the number of API requests and lines of intermediate code.

curl https://api.stripe.com/v1/customers/search \
  -u $API_KEY: \
  --data-urlencode query="email:'test@example.com'" \
  -d "expand[]"="data.subscriptions" \
  -G

This would be a two-step process:

First, find the ID of the customer by using their email like this:

curl https://api.stripe.com/v1/customers \
  -u sk_xxx: \
  -d email=foo@bar.com \
  -G

Second, use the customer ID to list all their subscriptions like this:

curl https://api.stripe.com/v1/subscriptions \
  -u sk_xxx: \
  -d customer=cu_xxx \
  -G
Related