Attempting to create a product on stripe dashboard through node-fetch.
code snippet:
async createProduct(data) {
try {
const response = await fetch(url, {
method: 'POST',
headers: {
'Authorization': `Bearer ${process.env.STRIPE_SECRET_KEY}`,
'Content-Type': 'application/x-www-form-urlencoded'
},
body: new URLSearchParams(Object.entries(data)).toString()}).then(res => res.json());
return { data: response };
} catch (err) {
return { error: err.message };
}
}
JSON Body:
{
"name": "product",
"active": true,
"default_price_data": {
"currency": "eur",
"unit_amount": "1"
},
"description": "myprod",
"type": "service"
}
without the default price data it creates the product normally, but it's without a price of course. i need help with the JSON body to initialize properly the default_price_data stuff and in the future for similar data structures.
Specifying type=service
on a product is not something you should do if your API version is less than 6 years old, which I hope it is.
https://docs.stripe.com/upgrades#2018-02-05
You should remove the type
argument from your payload, it should always be service
by default anyhow.