Sample code for 30+ languages & platforms
Tcl

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 Tcl Downloads

Tcl

load ./chilkat.dll

set success 0

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

set http [new_CkHttp]

# 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"
#           }
#         ]
#       }
#     ]
#   }
# }

set json [new_CkJsonObject]

CkJsonObject_UpdateString $json "product.name" "T-shirt"
CkJsonObject_UpdateString $json "product.productType" "physical"
CkJsonObject_UpdateNumber $json "product.priceData.price" "10.5"
CkJsonObject_UpdateString $json "product.description" "nice summer t-shirt"
CkJsonObject_UpdateString $json "product.sku" "123df"
CkJsonObject_UpdateBool $json "product.visible" 0
CkJsonObject_UpdateNumber $json "product.weight" "0.2"
CkJsonObject_UpdateString $json "product.discount.type" "AMOUNT"
CkJsonObject_UpdateInt $json "product.discount.value" 1
CkJsonObject_UpdateBool $json "product.manageVariants" 1
CkJsonObject_UpdateString $json "product.productOptions[0].name" "Size"
CkJsonObject_UpdateString $json "product.productOptions[0].choices[0].value" "S"
CkJsonObject_UpdateString $json "product.productOptions[0].choices[0].description" "S"
CkJsonObject_UpdateString $json "product.productOptions[0].choices[1].value" "L"
CkJsonObject_UpdateString $json "product.productOptions[0].choices[1].description" "L"

CkHttp_put_AuthToken $http "ACCESS_TOKEN"

set resp [new_CkHttpResponse]

set success [CkHttp_HttpJson $http "POST" "https://www.wixapis.com/stores/v1/products" $json "application/json" $resp]
if {$success == 0} then {
    puts [CkHttp_lastErrorText $http]
    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkHttpResponse $resp
    exit
}

set sbResponseBody [new_CkStringBuilder]

CkHttpResponse_GetBodySb $resp $sbResponseBody
set jResp [new_CkJsonObject]

CkJsonObject_LoadSb $jResp $sbResponseBody
CkJsonObject_put_EmitCompact $jResp 0

puts "Response Body:"
puts [CkJsonObject_emit $jResp]

set respStatusCode [CkHttpResponse_get_StatusCode $resp]
puts "Response Status Code = $respStatusCode"
if {$respStatusCode >= 400} then {
    puts "Response Header:"
    puts [CkHttpResponse_header $resp]
    puts "Failed."
    delete_CkHttp $http
    delete_CkJsonObject $json
    delete_CkHttpResponse $resp
    delete_CkStringBuilder $sbResponseBody
    delete_CkJsonObject $jResp
    exit
}

# 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

set productId [CkJsonObject_stringOf $jResp "product.id"]
set productName [CkJsonObject_stringOf $jResp "product.name"]
set productSlug [CkJsonObject_stringOf $jResp "product.slug"]
set productVisible [CkJsonObject_BoolOf $jResp "product.visible"]
set productProductType [CkJsonObject_stringOf $jResp "product.productType"]
set productDescription [CkJsonObject_stringOf $jResp "product.description"]
set productStockTrackInventory [CkJsonObject_BoolOf $jResp "product.stock.trackInventory"]
set productStockInStock [CkJsonObject_BoolOf $jResp "product.stock.inStock"]
set productPriceCurrency [CkJsonObject_stringOf $jResp "product.price.currency"]
set productPricePrice [CkJsonObject_stringOf $jResp "product.price.price"]
set productPriceDiscountedPrice [CkJsonObject_stringOf $jResp "product.price.discountedPrice"]
set productPriceFormattedPrice [CkJsonObject_stringOf $jResp "product.price.formatted.price"]
set productPriceFormattedDiscountedPrice [CkJsonObject_stringOf $jResp "product.price.formatted.discountedPrice"]
set productPriceDataCurrency [CkJsonObject_stringOf $jResp "product.priceData.currency"]
set productPriceDataPrice [CkJsonObject_stringOf $jResp "product.priceData.price"]
set productPriceDataDiscountedPrice [CkJsonObject_stringOf $jResp "product.priceData.discountedPrice"]
set productPriceDataFormattedPrice [CkJsonObject_stringOf $jResp "product.priceData.formatted.price"]
set productPriceDataFormattedDiscountedPrice [CkJsonObject_stringOf $jResp "product.priceData.formatted.discountedPrice"]
set productManageVariants [CkJsonObject_BoolOf $jResp "product.manageVariants"]
set productProductPageUrlBase [CkJsonObject_stringOf $jResp "product.productPageUrl.base"]
set productProductPageUrlPath [CkJsonObject_stringOf $jResp "product.productPageUrl.path"]
set productNumericId [CkJsonObject_stringOf $jResp "product.numericId"]
set productInventoryItemId [CkJsonObject_stringOf $jResp "product.inventoryItemId"]
set productDiscountType [CkJsonObject_stringOf $jResp "product.discount.type"]
set productDiscountValue [CkJsonObject_IntOf $jResp "product.discount.value"]
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "product.additionalInfoSections"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "product.ribbons"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "product.media.items"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "product.customTextFields"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "product.productOptions"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set optionType [CkJsonObject_stringOf $jResp "product.productOptions[i].optionType"]
    set name [CkJsonObject_stringOf $jResp "product.productOptions[i].name"]
    set j 0
    set count_j [CkJsonObject_SizeOfArray $jResp "product.productOptions[i].choices"]
    while {$j < $count_j} {
        CkJsonObject_put_J $jResp $j
        set value [CkJsonObject_stringOf $jResp "product.productOptions[i].choices[j].value"]
        set description [CkJsonObject_stringOf $jResp "product.productOptions[i].choices[j].description"]
        set inStock [CkJsonObject_BoolOf $jResp "product.productOptions[i].choices[j].inStock"]
        set visible [CkJsonObject_BoolOf $jResp "product.productOptions[i].choices[j].visible"]
        set j [expr $j + 1]
    }
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "product.collectionIds"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set i [expr $i + 1]
}
set i 0
set count_i [CkJsonObject_SizeOfArray $jResp "product.variants"]
while {$i < $count_i} {
    CkJsonObject_put_I $jResp $i
    set id [CkJsonObject_stringOf $jResp "product.variants[i].id"]
    set choicesSize [CkJsonObject_stringOf $jResp "product.variants[i].choices.Size"]
    set variantPriceDataCurrency [CkJsonObject_stringOf $jResp "product.variants[i].variant.priceData.currency"]
    set variantPriceDataPrice [CkJsonObject_stringOf $jResp "product.variants[i].variant.priceData.price"]
    set variantPriceDataDiscountedPrice [CkJsonObject_stringOf $jResp "product.variants[i].variant.priceData.discountedPrice"]
    set variantPriceDataFormattedPrice [CkJsonObject_stringOf $jResp "product.variants[i].variant.priceData.formatted.price"]
    set variantPriceDataFormattedDiscountedPrice [CkJsonObject_stringOf $jResp "product.variants[i].variant.priceData.formatted.discountedPrice"]
    set variantWeight [CkJsonObject_IntOf $jResp "product.variants[i].variant.weight"]
    set variantVisible [CkJsonObject_BoolOf $jResp "product.variants[i].variant.visible"]
    set i [expr $i + 1]
}

delete_CkHttp $http
delete_CkJsonObject $json
delete_CkHttpResponse $resp
delete_CkStringBuilder $sbResponseBody
delete_CkJsonObject $jResp