I call /api.bigcommerce.com/stores/{$$.env.store_hash}/v3/carts with the following body
{
"line_items": [
{
"quantity": 5,
"product_id": 149,
"variant_id": 160,
"option_selections": [
{
"option_id": 72,
"option_value": "test"
}
]
}
]
}
The variant_id value is my product base_variant_id. I needed to add the variant_id otherwise the api call responds with
"errors": {
"variant": "This product has options, variant ID is required"
},
"status": 422,
"title": "Missing or incorrect required fields",
"type": "https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes"
}
Adding the variant_id got rid of the above error
When I make the POST api call, to add to the card, it complains that the sized option isn't set
{
"detail": "Please enter some text for the sized option.",
"status": 422,
"title": "Missing or incomplete product variant attributes",
"type": "https://developer.bigcommerce.com/api-docs/getting-started/api-status-codes"
}
How do I set the sized options value?
There are two types of “Options” in BigCommerce - one of them is called “Customizations”, the other is called “Variations”.
The difference between the two is that Variations will split your main product down into several “Variants” - these are essentially entirely different iterations of your main product - imagine the same shirt that is made out of cotton vs wool. When you build out a variation, BigCommerce will auto-generate entirely new Variant objects with unique SKU as variant children of the top level product. (If you have a newer store on the V3 products API.)
Customizations, however, do not generate new variants. Consider a silver ring with an option for an engraving - the engraving would not require a brand new “product child type” to be created in the system, it would simply be something that the store owner would customize each time the silver ring was ordered with that option - the base product is the same
You will want to inspect your product in the V3 API with the query string added to the request to expose variants. Instead of using the base_variant_id of the top level product, use the id of the variants that BC has auto-generated for your product.
Alternatively, to see what the variant ID for that option is on the front-end, console log out response.data of the productAttributesChanged function in product-details.js when you select that option you set on the product page itself - BC will return a response object with the variant ID as well