Sample code for 30+ languages & platforms
Lua

WiX Create Product

See more WiX Examples

Creates a new product.

Note: If you get a 403 error response, try refreshing the access token.

Chilkat Lua Downloads

Lua
local chilkat = require("chilkat")

-- This example assumes the Chilkat API to have been previously unlocked.
-- See Global Unlock Sample for sample code.

local http = chilkat.Http.new()

-- Implements the following CURL command:

-- curl -X POST \
--    'https://www.wixapis.com/stores/v1/products' \
--     --data-binary '{
--                      "product": {
--                        "name": "T-shirt",
--                        "productType": "physical",
--                        "priceData": {
--                          "price": 10.5
--                        },
--                        "description": "nice summer t-shirt",
--                        "sku": "123df",
--                        "visible": false,
--                        "weight": 0.2,
--                        "discount": {
--                            "type": "AMOUNT",
--                            "value": 1
--                        },
--                        "manageVariants": true,
--                        "productOptions": [
--                          {
--                            "name": "Size",
--                            "choices": [
--                              {
--                                "value": "S",
--                                "description": "S"
--                              },
--                              {
--                                "value": "L",
--                                "description": "L"
--                              }
--                            ]
--                          }
--                        ]
--                      }
--                    }' \
--    -H 'Content-Type: application/json' \
--    -H 'Authorization: <AUTH>'

-- Use the following online tool to generate HTTP code from a CURL command
-- Convert a cURL Command to HTTP Source Code

-- Use this online tool to generate code from sample JSON:
-- Generate Code to Create JSON

-- The following JSON is sent in the request body.

-- {
--   "product": {
--     "name": "T-shirt",
--     "productType": "physical",
--     "priceData": {
--       "price": 10.5
--     },
--     "description": "nice summer t-shirt",
--     "sku": "123df",
--     "visible": false,
--     "weight": 0.2,
--     "discount": {
--       "type": "AMOUNT",
--       "value": 1
--     },
--     "manageVariants": true,
--     "productOptions": [
--       {
--         "name": "Size",
--         "choices": [
--           {
--             "value": "S",
--             "description": "S"
--           },
--           {
--             "value": "L",
--             "description": "L"
--           }
--         ]
--       }
--     ]
--   }
-- }

local json = chilkat.JsonObject.new()
json:update_string("product.name", "T-shirt")
json:update_string("product.productType", "physical")
json:update_number("product.priceData.price", "10.5")
json:update_string("product.description", "nice summer t-shirt")
json:update_string("product.sku", "123df")
json:update_bool("product.visible", false)
json:update_number("product.weight", "0.2")
json:update_string("product.discount.type", "AMOUNT")
json:update_int("product.discount.value", 1)
json:update_bool("product.manageVariants", true)
json:update_string("product.productOptions[0].name", "Size")
json:update_string("product.productOptions[0].choices[0].value", "S")
json:update_string("product.productOptions[0].choices[0].description", "S")
json:update_string("product.productOptions[0].choices[1].value", "L")
json:update_string("product.productOptions[0].choices[1].description", "L")

http.auth_token = "ACCESS_TOKEN"

local resp = chilkat.HttpResponse.new()
local success = http:http_json("POST", "https://www.wixapis.com/stores/v1/products", json, "application/json", resp)
if not success then
    print(http.last_error_text)
    return
end

local sbResponseBody = chilkat.StringBuilder.new()
resp:get_body_sb(sbResponseBody)
local jResp = chilkat.JsonObject.new()
jResp:load_sb(sbResponseBody)
jResp.emit_compact = false

print("Response Body:")
print(jResp:emit())

local respStatusCode = resp.status_code
print("Response Status Code = " .. respStatusCode)
if respStatusCode >= 400 then
    print("Response Header:")
    print(resp.header)
    print("Failed.")
    return
end

-- Sample JSON response:
-- (Sample code for parsing the JSON response is shown below)

-- {
--   "product": {
--     "id": "e28e4ddd-6ed0-4098-a5e5-cf4bd9c4f7b5",
--     "name": "T-shirt",
--     "slug": "t-shirt-1",
--     "visible": false,
--     "productType": "physical",
--     "description": "nice summer t-shirt",
--     "stock": {
--       "trackInventory": false,
--       "inStock": true
--     },
--     "price": {
--       "currency": "ILS",
--       "price": 10.5,
--       "discountedPrice": 9.5,
--       "formatted": {
--         "price": "10.50",
--         "discountedPrice": "9.50"
--       }
--     },
--     "priceData": {
--       "currency": "ILS",
--       "price": 10.5,
--       "discountedPrice": 9.5,
--       "formatted": {
--         "price": "10.50",
--         "discountedPrice": "9.50"
--       }
--     },
--     "additionalInfoSections": [
--     ],
--     "ribbons": [
--     ],
--     "media": {
--       "items": [
--       ]
--     },
--     "customTextFields": [
--     ],
--     "manageVariants": true,
--     "productOptions": [
--       {
--         "optionType": "drop_down",
--         "name": "Size",
--         "choices": [
--           {
--             "value": "S",
--             "description": "S",
--             "inStock": true,
--             "visible": true
--           },
--           {
--             "value": "L",
--             "description": "L",
--             "inStock": true,
--             "visible": true
--           }
--         ]
--       }
--     ],
--     "productPageUrl": {
--       "base": "https://www.itsjusttooeasy123.com/",
--       "path": "/product-page/t-shirt-1"
--     },
--     "numericId": "1567588455405000",
--     "inventoryItemId": "1d71b222-912f-bf67-5a1a-30b4263b084a",
--     "discount": {
--       "type": "AMOUNT",
--       "value": 1
--     },
--     "collectionIds": [
--     ],
--     "variants": [
--       {
--         "id": "00000000-0000-0001-0005-93fc95e0514a",
--         "choices": {
--           "Size": "S"
--         },
--         "variant": {
--           "priceData": {
--             "currency": "ILS",
--             "price": 10.5,
--             "discountedPrice": 9.5,
--             "formatted": {
--               "price": "10.50",
--               "discountedPrice": "9.50"
--             }
--           },
--           "weight": 10,
--           "visible": true
--         }
--       },
--       {
--         "id": "00000000-0000-0002-0005-93fc95e0514a",
--         "choices": {
--           "Size": "L"
--         },
--         "variant": {
--           "priceData": {
--             "currency": "ILS",
--             "price": 10.5,
--             "discountedPrice": 9.5,
--             "formatted": {
--               "price": "10.50",
--               "discountedPrice": "9.50"
--             }
--           },
--           "visible": true
--         }
--       }
--     ]
--   }
-- }

-- Sample code for parsing the JSON response...
-- Use the following online tool to generate parsing code from sample JSON:
-- Generate Parsing Code from JSON

local optionType = ""
local name = ""
local j = 0
local count_j = 0
local value = ""
local description = ""
local inStock = false
local visible = false
local id = ""
local choicesSize = ""
local variantPriceDataCurrency = ""
local variantPriceDataPrice = ""
local variantPriceDataDiscountedPrice = ""
local variantPriceDataFormattedPrice = ""
local variantPriceDataFormattedDiscountedPrice = ""
local variantWeight = 0
local variantVisible = false

local productId = jResp:string_of("product.id")
local productName = jResp:string_of("product.name")
local productSlug = jResp:string_of("product.slug")
local productVisible = jResp:bool_of("product.visible")
local productProductType = jResp:string_of("product.productType")
local productDescription = jResp:string_of("product.description")
local productStockTrackInventory = jResp:bool_of("product.stock.trackInventory")
local productStockInStock = jResp:bool_of("product.stock.inStock")
local productPriceCurrency = jResp:string_of("product.price.currency")
local productPricePrice = jResp:string_of("product.price.price")
local productPriceDiscountedPrice = jResp:string_of("product.price.discountedPrice")
local productPriceFormattedPrice = jResp:string_of("product.price.formatted.price")
local productPriceFormattedDiscountedPrice = jResp:string_of("product.price.formatted.discountedPrice")
local productPriceDataCurrency = jResp:string_of("product.priceData.currency")
local productPriceDataPrice = jResp:string_of("product.priceData.price")
local productPriceDataDiscountedPrice = jResp:string_of("product.priceData.discountedPrice")
local productPriceDataFormattedPrice = jResp:string_of("product.priceData.formatted.price")
local productPriceDataFormattedDiscountedPrice = jResp:string_of("product.priceData.formatted.discountedPrice")
local productManageVariants = jResp:bool_of("product.manageVariants")
local productProductPageUrlBase = jResp:string_of("product.productPageUrl.base")
local productProductPageUrlPath = jResp:string_of("product.productPageUrl.path")
local productNumericId = jResp:string_of("product.numericId")
local productInventoryItemId = jResp:string_of("product.inventoryItemId")
local productDiscountType = jResp:string_of("product.discount.type")
local productDiscountValue = jResp:int_of("product.discount.value")
local i = 0
local count_i = jResp:size_of_array("product.additionalInfoSections")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("product.ribbons")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("product.media.items")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("product.customTextFields")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("product.productOptions")
while i < count_i do
    jResp.i = i
    optionType = jResp:string_of("product.productOptions[i].optionType")
    name = jResp:string_of("product.productOptions[i].name")
    j = 0
    count_j = jResp:size_of_array("product.productOptions[i].choices")
    while j < count_j do
        jResp.j = j
        value = jResp:string_of("product.productOptions[i].choices[j].value")
        description = jResp:string_of("product.productOptions[i].choices[j].description")
        inStock = jResp:bool_of("product.productOptions[i].choices[j].inStock")
        visible = jResp:bool_of("product.productOptions[i].choices[j].visible")
        j = j + 1
    end

    i = i + 1
end

i = 0
count_i = jResp:size_of_array("product.collectionIds")
while i < count_i do
    jResp.i = i
    i = i + 1
end

i = 0
count_i = jResp:size_of_array("product.variants")
while i < count_i do
    jResp.i = i
    id = jResp:string_of("product.variants[i].id")
    choicesSize = jResp:string_of("product.variants[i].choices.Size")
    variantPriceDataCurrency = jResp:string_of("product.variants[i].variant.priceData.currency")
    variantPriceDataPrice = jResp:string_of("product.variants[i].variant.priceData.price")
    variantPriceDataDiscountedPrice = jResp:string_of("product.variants[i].variant.priceData.discountedPrice")
    variantPriceDataFormattedPrice = jResp:string_of("product.variants[i].variant.priceData.formatted.price")
    variantPriceDataFormattedDiscountedPrice = jResp:string_of("product.variants[i].variant.priceData.formatted.discountedPrice")
    variantWeight = jResp:int_of("product.variants[i].variant.weight")
    variantVisible = jResp:bool_of("product.variants[i].variant.visible")
    i = i + 1
end