I’m trying to add a product through wix-stores-backend api.
I’m using createProduct(myProduct) as shown in the api reference, but i keep getting an “empty” error.
The error returns: {“error”:{“message”:“”,“details”:{}}}
I’m kind of lost here and would be happy for any tips on how to solve this.
// Frontend
export async function get_test123(request){
const response = {
"headers": {
"Content-Type": "application/json"
}
};
const myProduct = {
"name": "Car Model YO-124",
"description": "The classiest model in our unique, well-engineered line of luxury cars.",
"price": 79000,
"discount": {
"type": "AMOUNT",
"value": 5
},
"productOptions": {
"Color": {
"choices": [{
"description": "Metallic silver",
"value": "Silver",
"mainMedia": "wix:image://light-silver.jpg/file.jpg#originWidth=4896&originHeight=3264",
"mediaItems": [{
"src": "wix:image://v1/light-silver-front-view.jpg/file.jpg#originWidth=1000&originHeight=1000",
"description": "Front view of car",
"title": "Front view of light silver car",
"type": "Image"
},
{
"src": "wix:image://v1/light-silver-side-view.jpg/file.jpg#originWidth=1000&originHeight=1000",
"description": "Side view of car",
"title": "Side view of light silver car",
"type": "Image"
}
],
},
{
"description": "Metallic black",
"value": "Black",
"mainMedia": "wix:image://black.jpg/file.jpg#originWidth=4896&originHeight=3264"
}
]
}
},
"manageVariants": true,
"productType": "physical",
"weight": 1000.0
}
var newProduct = await createProductBackend(myProduct)
.then( (result) => {
response.body = {"insert": newProduct};
return result;
} )
.catch( (error) => {
response.body = {"error": error};
return error;
});
return ok(response);
}
//backend
export function createProductBackend(product){
return wixStoresBackend.createProduct(product);
}