How to create product in stripe with stripe API?

https://stripe.com/docs/api/products/create I tried with ChatGPT but - no success
Stripe API reference – Create a product – curl
Complete reference documentation for the Stripe API. Includes code snippets and examples for our Python, Java, PHP, Node.js, Go, Ruby, and .NET libraries.
2 Replies
vince
vince15mo ago
Do you have the stripe types library installed? I haven't worked with Stripe -- but I know some packages don't come with the types by default so you have to install it separately
Nikita
NikitaOP15mo ago
Solved
//Create product on Stripe https://dashboard.stripe.com/test/products/create
const productResponse = await axios.post(
"https://api.stripe.com/v1/products",
{
name: title,
description: subTitle,
type: "good",
images: imagesArray,
},
{
headers: {
Authorization: `Bearer ${import.meta.env.VITE_STRIPE_SECRET}`,
"Content-Type": "application/x-www-form-urlencoded",
},
},
)

if (!productResponse.data.active) {
const activateResponse = await axios.put(
`https://api.stripe.com/v1/products/${productResponse.data.id}`,
{
active: true,
},
{
headers: {
Authorization: `Bearer ${import.meta.env.VITE_STRIPE_SECRET}`,
"Content-Type": "application/x-www-form-urlencoded",
},
},
)

if (activateResponse.data.active) {
console.log("Product activated:", activateResponse.data)
}
}

// Create price for the product
const priceResponse = await axios.post(
"https://api.stripe.com/v1/prices",
{
unit_amount: price * 100, // Convert to cents
currency: "usd",
product: productResponse.data.id,
},
{
headers: {
Authorization: `Bearer ${import.meta.env.VITE_STRIPE_SECRET}`,
"Content-Type": "application/x-www-form-urlencoded",
},
},
)
//Create product on Stripe https://dashboard.stripe.com/test/products/create
const productResponse = await axios.post(
"https://api.stripe.com/v1/products",
{
name: title,
description: subTitle,
type: "good",
images: imagesArray,
},
{
headers: {
Authorization: `Bearer ${import.meta.env.VITE_STRIPE_SECRET}`,
"Content-Type": "application/x-www-form-urlencoded",
},
},
)

if (!productResponse.data.active) {
const activateResponse = await axios.put(
`https://api.stripe.com/v1/products/${productResponse.data.id}`,
{
active: true,
},
{
headers: {
Authorization: `Bearer ${import.meta.env.VITE_STRIPE_SECRET}`,
"Content-Type": "application/x-www-form-urlencoded",
},
},
)

if (activateResponse.data.active) {
console.log("Product activated:", activateResponse.data)
}
}

// Create price for the product
const priceResponse = await axios.post(
"https://api.stripe.com/v1/prices",
{
unit_amount: price * 100, // Convert to cents
currency: "usd",
product: productResponse.data.id,
},
{
headers: {
Authorization: `Bearer ${import.meta.env.VITE_STRIPE_SECRET}`,
"Content-Type": "application/x-www-form-urlencoded",
},
},
)
Want results from more Discord servers?
Add your server