stripe-payments

Stripe - Error : This product cannot be deleted because it has one or more user-created prices


I tried calling Stripe Api to create a product with a default price .

stripe.products.create({
    name : name,
    description : description,
    metadata : {
        userID : profileId
    },
    default_price_data : {
        currency : "eur",
        unit_amount_decimal : price,
    },
    expand: ['default_price'],

},{
    stripeAccount : accountId
})

But when I tried to delete the created product it gave me an error which says:

This product cannot be deleted because it has one or more user-created prices.

Then , I tried to delete the Associated Price to the product.

Surprisingly, There isn't a stripe call to delete a price ! so I just tried to make active=false by calling update price call :

stripe.prices.update(stripePriceId , { active : false} ,{
    stripeAccount : stripeAccountId
} )

Unfortunately , I still got the same error. How can I delete this product?

For technical reasons : I must delete the product using Stripe API and not Stripe Dashboard


Solution

  • Unfortunately this is just impossible. Once a Product has associated Prices, it can not be deleted via the API. This is a limitation of Stripe's API as they discourage data deletion in general. Instead they recommend setting active: false on the Product and/or the Prices directly.

    This ensures that you have complete data in your system when you do data analysis or reconciliation later and avoids developers deleting data now they will likely need in months or years down the road and regret deleting.

    The Dashboard option is here more as an escape hatch that you wouldn't use at scale.