Home > other >  Stripe - expand Product data with Prices
Stripe - expand Product data with Prices

Time:08-09

Basically I'm just trying to expand the product call in stripe with prices, so I don't have to make another API for each product that's retrieved.

Product.list(ProductListParams.builder()
                    .setActive(true)
                    .addExpand("data.prices")
                    .build());

I've tried both data.prices and data.price but the Product Collection response -> defaultPrice is still just returning the prices id with a null expandable object.

I've also tried data.defaultPrice, but the call fails completely in this case.

Thanks all.

CodePudding user response:

Unfortunately you can't list all of a product's prices from the list products call. To get a full list of prices by product, you will need to make a List Prices call for each product ID that you want the prices for.[1]

The reason that you are getting an error is that Stripe's Product objects do not have a prices field to expand. This call will work if you specify an expandable field that products do have such as default_price.

[1] https://site-admin.stripe.com/docs/api/prices/list#list_prices-product

[2] https://site-admin.stripe.com/docs/api/products/object

  • Related