Reputation: 15377
How does one go about creating a new product with variations via the API?
Let's say I want to create a brand new product with 2 types of variation: Size (S, M, L) and Color (Red, Green).
It sounds like to do this, I need to use the SKU endpoint instead of the normal product endpoint. But to create a product SKU, I need to call https://developer.bigcommerce.com/api/stores/v2/products/skus#update-a-product-sku . To call that API, I need a product ID... so clearly I need to make the product first.
To make the product I call https://developer.bigcommerce.com/api/stores/v2/products#create-a-product . I want inventory_tracking=sku, but I get an error on a new product saying I cannot do inventory_tracking=sku without skus being enabled. So I guess I need to make a simple product first and update it later?
So I am trying to do something like this as my workflow
1) Create a new product with inventory tracking = simple
2) Create a new Option for Size via a post to /options
3) Add the values, S, M, L via posts to /options/option id from #2/values
4) Create a new Option for Color via a post to /options
5) Add the values Red, Green via posts to /options/option id from #4/values
6) Post to the skus endpoint 6 times, one per combination of Size / Color. For each I list a SKU, Price, option_value_id, product_option_id
{
"sku": "SKU-RED-SMALL",
"price": 5.00,
"weight": 1.00,
"options": [
{
"option_value_id": id-for-red,
"product_option_id": id-for-color
},
{
"option_value_id": id-for-small,
"product_option_id": id-for-size
},
],
}
7) I go back and update the product inventory_tracking to be SKU
This is the best plan I can figure out to get a single product listed.. but at #6 I am hitting an error "The field 'product_option_id' is invalid." I am guessing it could be because I created an "option" instead of a "product_option", but I do not see a way to create product_options.
Clearly there has to be an easier way? What is the best course to create this single listing with variations via the API?
Upvotes: 1
Views: 954
Reputation: 1866
Hopefully this helps clarify some of the workflow for how you create variants for something like small, medium, large, and red, blue, green. Colors are an option and sizes are an option. Both of these have to be assigned to an option set which is then associated with a product.
Upvotes: 1