#raf1.
1 messages ยท Page 1 of 1 (latest)
Hi, that is because you can't delete a price. Instead, you'd want to inactivate it so it can't be used again: https://stripe.com/docs/api/prices/update#update_price-active
Alright, will try that in a sec. Wll let you know how it went!
Sure!
So I've been trying to do
await stripe.prices.update(payload.price_id, {
active: false,
})
const product = await stripe.products.del(payload.product_id)
But I get response with message
This price cannot be archived because it is the default price of its product.
Ah, that is because you can't archive the default price. You can update the product, https://stripe.com/docs/api/products/update#update_product-default_price with another default price and then inactivate the old default price.
Hmm, can I use any different approach to avoid doing extra update on product?
Create product without default_price_data and then attach it along creating price via stripe.prices.create ?
That is not possible I'm afraid
You would need to make a call to upadte the default price of the Product
So Product requires default price to be provided?
From the docs I see that only name is required, and then default_price_data.currency but default_price_data is not
When you create the price, it pulls in as the default price for that product, https://stripe.com/docs/api/prices/create#create_price-product_data-name.
I've created a Product without providing any Price data.
Then create Price with product provided
Like so
const stripeProduct = await stripe.products.create({
name: payload.name,
})
const stripePrice = await stripe.prices.create({
currency: 'eur',
unit_amount: payload.price,
product: stripeProduct.id,
})
That is right, and if you look at that price it would be the default price of that product now.
It is not, default_price is null
๐ stepping in here and catching up
Yeah what you stated about the default is expected -- it isn't set on creation.
I'm not sure the confusion exactly, but you should be able to pass an empty string to unset the default_price if I remember correctly. Otherwise, just don't set it in the first place if you want to archive.
I did it like my last code snippet states, but while trying to delete the product, response for deleting is
This product cannot be deleted because it has one or more user-created prices.
In Stripe dashboard I can see that the Price that is attached to Product - has been archived successfully
Sure, as stated you can't delete Products/Prices that have been used.
You just archive them
That is the extent that you can action them
You can delete if it is a Product with a Price that has never been used for a transaction
Otherwise you can't
It wasn't used at all
I'm working on CRUD for my app that includes Stripe Products, simply created Product via my app, then I want to delete it to test deletion.
Okay give me a sec
Okay I just checked and it does look like the Dashboard uses a different path here that allows deletion in this case whereas it is blocked via the API.
I can file feedback internally to get this ability added to the API, similar to the Dashboard, but for now this isn't possible via the API
You are best off archiving for now
alright
And shouldnt stripe.products.list() and stripe.prices.list() return non-archived (active) Products / Prices?
I should pass active: true param probably. Might be worth to set it as default.
Yeah you would need to pass active: true for that behavior as you noted