beehexa integrationsidebar
beehexa beehexa logo 1

We Build HexaSync Integration Platform for Connecting ERP, POS, CRM, Accounting, and eCommerce Applications to Automate Business Processes

BigCommerce API 2024: How To Retrieve And Create A Product Variant Without Error 409

Variations are used for products that are available in different colors, sizes, or styles. Each variant can have its own image, price, and weight, and they typically have its own SKU and stock level.

Variant options can be displayed as one of four multiple-choice types:

  • Swatch
  • Radio Buttons
  • Rectangle List
  • Dropdown

Getting information and creating new variants is very important in product classification, inventory management, etc. That’s why I decided to publish this article.

First of all, we need to check the BigCommerce store to see all the Products that are available right now and a variant of a product you want to create. Then we also need to get the ID of the product in which you want to create a new product variant. You can read the blog: BigCommerce API 2023: How To Retrieve Product Data or BigCommerce Product API 2023: How to create a product to know more.

beehexa 1 how to retrieve and create a product variant without error 409 1
beehexa 1 how to retrieve and create a product variant without error 409 1

Retrieving All Product Variant

Log in to Postman, choose a workspace, and open a new request tab. Here, select GET and paste the URL:  

https://api.bigcommerce.com/stores/{store_hash}/v3/catalog/products/{product_id}/variants

Replace Store hash with your store hash and product ID by the product id you want to see the variants

Now in the header section, fill in the information about:

  • X-auth-token
  • Accept
  • Content-type

After all, click send button to see the result:

{
    "data": [
        {
            "id": 78,
            "product_id": 111,
            "sku": "SM13-RE",
            "sku_id": 127,
            "price": null,
            "calculated_price": 25,
            "sale_price": null,
            "retail_price": null,
            "map_price": null,
            "weight": null,
            "calculated_weight": 1,
            "width": null,
            "height": null,
            "depth": null,
            "is_free_shipping": false,
            "fixed_cost_shipping_price": null,
            "purchasing_disabled": false,
            "purchasing_disabled_message": "",
            "image_url": "",
            "cost_price": null,
            "upc": "",
            "mpn": "",
            "gtin": "",
            "inventory_level": 0,
            "inventory_warning_level": 0,
            "bin_picking_number": "",
            "option_values": [
                {
                    "id": 102,
                    "label": "Red",
                    "option_id": 113,
                    "option_display_name": "Color"
                }
            ]
        }
 "meta": {
        "pagination": {
            "total": 5,
            "count": 5,
            "per_page": 50,
            "current_page": 1,
            "total_pages": 1,
            "links": {
                "current": "?page=1&limit=50"
            }
        }
    }
}
Code language: JSON / JSON with Comments (json)
beehexa 3 how to retrieve and create a product variant without error 409

Create A New Product Variant Without error 409: “A variant option values should correspond to the product’s existing option values”

For a new variant created separately from the base and its existing variants, the request body needs to reference the option choices and their values by ID. (This means that the options must already exist in the store.) Here is an example request body:

{
    "sku": "New-SKU",

    "option_values": [

        {
            "id": "option_value ID",
            "option_id": "option ID"
        }
    ]
}
Code language: JSON / JSON with Comments (json)

Get the option ID from product/[product_id]/options before creating a new option value

Select get and paste the URL: https://api.bigcommerce.com/stores/{store_hash}/v3/catalog/products/{product_id}/options

After having the information on the option ID and its option value ID you can create a new variant for it.

If you want to create a new option value for an existing option, then open a new request tab, select POST, and paste the following URL:

https://api.bigcommerce.com/stores/{store_hash}/v3/catalog/products/{product_id/options/{option_id}/values

The header part does not change, go to the body, select raw, and choose JSON. Then add the following to the body to create a new option value, for example:

{
      "is_default": false,
      "sort_order": 3,
      "label": "White"
}
Code language: JSON / JSON with Comments (json)

And result

beehexa how to retrieve and create a product variant without error 409
beehexa how to retrieve and create a product variant without error 409

And we will get the information of the newly created option value and it contains the option values ID

And now we have all the information we need to create a new product variant.

Open a new request tab, this time select POST and paste the URL: https://api.bigcommerce.com/stores/{store_hash}/v3/catalog/products/{product_id}/variants

The same as retrieving the products variant, you have to replace the store hash and product ID.

In the header section, fill in the information about:

  • X-auth-token
  • Accept
  • Content-type

In the body section:

Creates a Product Variant that needs the following information:

  • SKU
  • Option_values

It is important to note that a product cannot have more than 600 SKUs, and each SKU cannot exceed 255 characters long.

The model for a POST to create variants on a product.

{
    "sku": "New-SKU",
    "option_values": [
        {
            "id": "option_value ID",
             "option_id": "option ID"
        }
    ]
}

Code language: JSON / JSON with Comments (json)

The result will be like this 

beehexa 4 how to retrieve and create a product variant without error 409

Now you can turn back to BigCommerce to see the results

beehexa 5 how to retrieve and create a product variant without error 409

The above are steps to retrieve and create a new product variant in BigCommerce Using Postman. Getting a list of product variants using the BigCommerce API is relatively easy. Creating a new product variant is also not too hard. You need to follow the steps that I instructed above. If you have any difficulty or questions at any step, please comment below or refer to our BigCommerce API documentation if you have any questions.

Hope you are successful

Table of Contents

Ready to integrate and automate at scale ?

Learn how HexaSync lets you build enterprise-grade integrations and automations without having to code.

Receive Exclusive Productivity Tips Directly in Your Inbox

We’ll email you 1-3 times per week—and never share your information.

Get started for free

You can’t add more hours to the day. Beehexa is the next best thing.