Sample code for 30+ languages & platforms
AutoIt

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

AutoIt
Local $bSuccess = False

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

$oHttp = ObjCreate("Chilkat.Http")

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

$oJson = ObjCreate("Chilkat.JsonObject")
$oJson.UpdateString("product.name","T-shirt")
$oJson.UpdateString("product.productType","physical")
$oJson.UpdateNumber("product.priceData.price","10.5")
$oJson.UpdateString("product.description","nice summer t-shirt")
$oJson.UpdateString("product.sku","123df")
$oJson.UpdateBool("product.visible",False)
$oJson.UpdateNumber("product.weight","0.2")
$oJson.UpdateString("product.discount.type","AMOUNT")
$oJson.UpdateInt("product.discount.value",1)
$oJson.UpdateBool("product.manageVariants",True)
$oJson.UpdateString("product.productOptions[0].name","Size")
$oJson.UpdateString("product.productOptions[0].choices[0].value","S")
$oJson.UpdateString("product.productOptions[0].choices[0].description","S")
$oJson.UpdateString("product.productOptions[0].choices[1].value","L")
$oJson.UpdateString("product.productOptions[0].choices[1].description","L")

$oHttp.AuthToken = "ACCESS_TOKEN"

$oResp = ObjCreate("Chilkat.HttpResponse")
$bSuccess = $oHttp.HttpJson("POST","https://www.wixapis.com/stores/v1/products",$oJson,"application/json",$oResp)
If ($bSuccess = False) Then
    ConsoleWrite($oHttp.LastErrorText & @CRLF)
    Exit
EndIf

$oSbResponseBody = ObjCreate("Chilkat.StringBuilder")
$oResp.GetBodySb($oSbResponseBody)
$oJResp = ObjCreate("Chilkat.JsonObject")
$oJResp.LoadSb($oSbResponseBody)
$oJResp.EmitCompact = False

ConsoleWrite("Response Body:" & @CRLF)
ConsoleWrite($oJResp.Emit() & @CRLF)

Local $iRespStatusCode = $oResp.StatusCode
ConsoleWrite("Response Status Code = " & $iRespStatusCode & @CRLF)
If ($iRespStatusCode >= 400) Then
    ConsoleWrite("Response Header:" & @CRLF)
    ConsoleWrite($oResp.Header & @CRLF)
    ConsoleWrite("Failed." & @CRLF)
    Exit
EndIf

; 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 $sOptionType
Local $sName
Local $iJ
Local $iCount_j
Local $sValue
Local $sDescription
Local $bInStock
Local $bVisible
Local $sId
Local $sChoicesSize
Local $sVariantPriceDataCurrency
Local $sVariantPriceDataPrice
Local $sVariantPriceDataDiscountedPrice
Local $sVariantPriceDataFormattedPrice
Local $sVariantPriceDataFormattedDiscountedPrice
Local $iVariantWeight
Local $bVariantVisible

Local $sProductId = $oJResp.StringOf("product.id")
Local $sProductName = $oJResp.StringOf("product.name")
Local $sProductSlug = $oJResp.StringOf("product.slug")
Local $bProductVisible = $oJResp.BoolOf("product.visible")
Local $sProductProductType = $oJResp.StringOf("product.productType")
Local $sProductDescription = $oJResp.StringOf("product.description")
Local $bProductStockTrackInventory = $oJResp.BoolOf("product.stock.trackInventory")
Local $bProductStockInStock = $oJResp.BoolOf("product.stock.inStock")
Local $sProductPriceCurrency = $oJResp.StringOf("product.price.currency")
Local $sProductPricePrice = $oJResp.StringOf("product.price.price")
Local $sProductPriceDiscountedPrice = $oJResp.StringOf("product.price.discountedPrice")
Local $sProductPriceFormattedPrice = $oJResp.StringOf("product.price.formatted.price")
Local $sProductPriceFormattedDiscountedPrice = $oJResp.StringOf("product.price.formatted.discountedPrice")
Local $sProductPriceDataCurrency = $oJResp.StringOf("product.priceData.currency")
Local $sProductPriceDataPrice = $oJResp.StringOf("product.priceData.price")
Local $sProductPriceDataDiscountedPrice = $oJResp.StringOf("product.priceData.discountedPrice")
Local $sProductPriceDataFormattedPrice = $oJResp.StringOf("product.priceData.formatted.price")
Local $sProductPriceDataFormattedDiscountedPrice = $oJResp.StringOf("product.priceData.formatted.discountedPrice")
Local $bProductManageVariants = $oJResp.BoolOf("product.manageVariants")
Local $sProductProductPageUrlBase = $oJResp.StringOf("product.productPageUrl.base")
Local $sProductProductPageUrlPath = $oJResp.StringOf("product.productPageUrl.path")
Local $sProductNumericId = $oJResp.StringOf("product.numericId")
Local $sProductInventoryItemId = $oJResp.StringOf("product.inventoryItemId")
Local $sProductDiscountType = $oJResp.StringOf("product.discount.type")
Local $iProductDiscountValue = $oJResp.IntOf("product.discount.value")
Local $i = 0
Local $iCount_i = $oJResp.SizeOfArray("product.additionalInfoSections")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("product.ribbons")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("product.media.items")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("product.customTextFields")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("product.productOptions")
While $i < $iCount_i
    $oJResp.I = $i
    $sOptionType = $oJResp.StringOf("product.productOptions[i].optionType")
    $sName = $oJResp.StringOf("product.productOptions[i].name")
    $iJ = 0
    $iCount_j = $oJResp.SizeOfArray("product.productOptions[i].choices")
    While $iJ < $iCount_j
        $oJResp.J = $iJ
        $sValue = $oJResp.StringOf("product.productOptions[i].choices[j].value")
        $sDescription = $oJResp.StringOf("product.productOptions[i].choices[j].description")
        $bInStock = $oJResp.BoolOf("product.productOptions[i].choices[j].inStock")
        $bVisible = $oJResp.BoolOf("product.productOptions[i].choices[j].visible")
        $iJ = $iJ + 1
    Wend
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("product.collectionIds")
While $i < $iCount_i
    $oJResp.I = $i
    $i = $i + 1
Wend
$i = 0
$iCount_i = $oJResp.SizeOfArray("product.variants")
While $i < $iCount_i
    $oJResp.I = $i
    $sId = $oJResp.StringOf("product.variants[i].id")
    $sChoicesSize = $oJResp.StringOf("product.variants[i].choices.Size")
    $sVariantPriceDataCurrency = $oJResp.StringOf("product.variants[i].variant.priceData.currency")
    $sVariantPriceDataPrice = $oJResp.StringOf("product.variants[i].variant.priceData.price")
    $sVariantPriceDataDiscountedPrice = $oJResp.StringOf("product.variants[i].variant.priceData.discountedPrice")
    $sVariantPriceDataFormattedPrice = $oJResp.StringOf("product.variants[i].variant.priceData.formatted.price")
    $sVariantPriceDataFormattedDiscountedPrice = $oJResp.StringOf("product.variants[i].variant.priceData.formatted.discountedPrice")
    $iVariantWeight = $oJResp.IntOf("product.variants[i].variant.weight")
    $bVariantVisible = $oJResp.BoolOf("product.variants[i].variant.visible")
    $i = $i + 1
Wend