Create an item with sizes and colors

To create products with combinations (i.e. size / color) it is first necessary to update the product by inserting the variants to be used: this is because the combinations must have the unique id of the variant, which is provided once they are entered.

By creating combination items, sales will be allowed in the following way:

  1. Sale with combination barcode: it will be possible to scan the combination barcode to make the sale
  2. Size / color selection on the UI: by selecting the generic item, the size / color selection will appear on the screen.

Therefore, at least two API calls are required to create the combinations.

First call

Create the variations (i.e. size and color)

POST /items/

{
    "on_sale": true,
    "category_id": 1,
    "name": "T-shirt Happy",
    "price1": 100,
    "department_id": 1,
    "variations": [
        {
            "name": "Size", // Label for the Variation
            "required": false,
            "variation_values": [
                {
                    "value": "L", // Label for the Variation's option
                    "price_difference": 0
                },
                {
                    "value": "M",
                    "price_difference": 0
                }
            ]
        },
        {
            "name": "Color", 
            "required": false,
            "variation_values": [
                {
                    "value": "Red",
                    "price_difference": 0
                },
                {
                    "value": "Black",
                    "price_difference": 0
                }
            ]
        }
    ]
}

Second call

Let's set the combinations. In the second phase the combinations must be indicated using the values of the variants obtained from the response of phase 1. For each combination, the prices of the 5 price lists, a sku and the barcodes to be associated with that combination can be indicated.
The combination_values must indicate the id of the variant (variation_id field) and the id of the value to be attributed (id field)

PUT /items/{item.id}

{
    "on_sale": true,
    "department_id": 1,
    "name": "T-shirt Happy",
    "favorite": false,
    "price1": 100,
    "category_id": 1,
    "variations": [
        {
            "name": "Size",
            "id": 45319,
            "required": false,
            "item_id": 45276,
            "variation_values": [
                {
                    "value": "L",
                    "default_value": false,
                    "id": 163864,
                    "variation_id": 45319
                },
                {
                    "value": "M",
                    "default_value": false,
                    "id": 163865,
                    "variation_id": 45319
                }
            ]
        },
        {
            "name": "Color",
            "id": 45320,
            "required": false,
            "item_id": 45276,
            "variation_values": [
                {
                    "value": "Red",
                    "default_value": false,
                    "id": 163866,
                    "variation_id": 45320
                },
                {
                    "value": "Black",
                    "default_value": false,
                    "id": 163867,
                    "variation_id": 45320
                }
            ]
        }
    ],
    "combinations": [
        {
            "combination_values": [
                {
                    "id": 163864, 				 // refer to the variation's option id returned by the first POST call
                    "variation_id": 45319  // refer to the variation id returned by the first POST call
                },
                {
                    "id": 163866,
                    "variation_id": 45320
                }
            ],
            "price1": 1,											// price of the combination color+size
            "barcodes": ['1234567890128']     // barcode of the combination color+size
        },
        {
            "combination_values": [
                {
                    "id": 163864,
                    "variation_id": 45319
                },
                {
                    "id": 163867,
                    "variation_id": 45320
                }
            ],
            "price1": 1,
            "barcodes": ['1234566v890123']
        },
        {
            "combination_values": [
                {
                    "id": 163865,
                    "variation_id": 45319
                },
                {
                    "id": 163866,
                    "variation_id": 45320
                }
            ],
            "price1": 1,
            "barcodes": ['1288867890129']
        },
        {
            "combination_values": [
                {
                    "id": 163865,
                    "variation_id": 45319
                },
                {
                    "id": 163867,
                    "variation_id": 45320
                }
            ],
            "price1": 1,
            "barcodes": ['1234567999121']
        }
    ]
}