bmiskie
bmiskie

Reputation: 627

How to gain access to pricing in tiers of a subscription with a single expanded request on a customer id

Previously in 2018-02-28 version of the stripe api, in request for subscriptions from a customer:

var customer = await stripe.customers.retrieve(
   stripe_customer_id_used,
   {
     expand: ['subscriptions'],
   }
);

the plan tier data list would be included in the response...in the latest 2020-08-27 version of the stripe api its missing the tier plan data list that is includes the pricing.

If attempting to expand the list this way:

var customer = await stripe.customers.retrieve(
   stripe_customer_id_used,
   {
     expand: ['subscriptions.data.items.data.plan.data.tiers'],
   }
);

I go beyond the "4 levels" rule.

Is there another to grab the plan tier data in a single request...or am i going to now have to loop through this response, and re-request this data from stripe adding many requests to stripe...which i want to avoid.

What am I missing? Any guidance would be appreciated!

Upvotes: 3

Views: 1831

Answers (1)

Justin Michael
Justin Michael

Reputation: 6495

This behavior changed in version 2020-08-27:

  • The subscriptions property on Customers is no longer included by default. You can expand the list but for performance reasons we recommended against doing so unless needed.
  • The tiers property on Plan is no longer included by default. You can expand the list but for performance reasons we recommended against doing so unless needed.

To work around this you can make this specific API request with the API version prior to the changes mentioned above, which is version 2020-03-02. Doing so would look something like this:

var customer = await stripe.customers.retrieve(
   stripe_customer_id_used,
   {
     expand: ['subscriptions'],
   },
   {
     apiVersion: '2020-03-02',
   }
);

Upvotes: 1

Related Questions