DataFlex
DataFlex
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 DataFlex Downloads
Use ChilkatAx-win32.pkg
Procedure Test
Boolean iSuccess
Handle hoHttp
Variant vJson
Handle hoJson
Variant vResp
Handle hoResp
Variant vSbResponseBody
Handle hoSbResponseBody
Handle hoJResp
Integer iRespStatusCode
String sOptionType
String sName
Integer j
Integer iCount_j
String sValue
String sDescription
Boolean iInStock
Boolean iVisible
String sId
String sChoicesSize
String sVariantPriceDataCurrency
String sVariantPriceDataPrice
String sVariantPriceDataDiscountedPrice
String sVariantPriceDataFormattedPrice
String sVariantPriceDataFormattedDiscountedPrice
Integer iVariantWeight
Boolean iVariantVisible
String sProductId
String sProductName
String sProductSlug
Boolean iProductVisible
String sProductProductType
String sProductDescription
Boolean iProductStockTrackInventory
Boolean iProductStockInStock
String sProductPriceCurrency
String sProductPricePrice
String sProductPriceDiscountedPrice
String sProductPriceFormattedPrice
String sProductPriceFormattedDiscountedPrice
String sProductPriceDataCurrency
String sProductPriceDataPrice
String sProductPriceDataDiscountedPrice
String sProductPriceDataFormattedPrice
String sProductPriceDataFormattedDiscountedPrice
Boolean iProductManageVariants
String sProductProductPageUrlBase
String sProductProductPageUrlPath
String sProductNumericId
String sProductInventoryItemId
String sProductDiscountType
Integer iProductDiscountValue
Integer i
Integer iCount_i
String sTemp1
Move False To iSuccess
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
Get Create (RefClass(cComChilkatHttp)) To hoHttp
If (Not(IsComObjectCreated(hoHttp))) Begin
Send CreateComObject of hoHttp
End
// 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"
// }
// ]
// }
// ]
// }
// }
Get Create (RefClass(cComChilkatJsonObject)) To hoJson
If (Not(IsComObjectCreated(hoJson))) Begin
Send CreateComObject of hoJson
End
Get ComUpdateString Of hoJson "product.name" "T-shirt" To iSuccess
Get ComUpdateString Of hoJson "product.productType" "physical" To iSuccess
Get ComUpdateNumber Of hoJson "product.priceData.price" "10.5" To iSuccess
Get ComUpdateString Of hoJson "product.description" "nice summer t-shirt" To iSuccess
Get ComUpdateString Of hoJson "product.sku" "123df" To iSuccess
Get ComUpdateBool Of hoJson "product.visible" False To iSuccess
Get ComUpdateNumber Of hoJson "product.weight" "0.2" To iSuccess
Get ComUpdateString Of hoJson "product.discount.type" "AMOUNT" To iSuccess
Get ComUpdateInt Of hoJson "product.discount.value" 1 To iSuccess
Get ComUpdateBool Of hoJson "product.manageVariants" True To iSuccess
Get ComUpdateString Of hoJson "product.productOptions[0].name" "Size" To iSuccess
Get ComUpdateString Of hoJson "product.productOptions[0].choices[0].value" "S" To iSuccess
Get ComUpdateString Of hoJson "product.productOptions[0].choices[0].description" "S" To iSuccess
Get ComUpdateString Of hoJson "product.productOptions[0].choices[1].value" "L" To iSuccess
Get ComUpdateString Of hoJson "product.productOptions[0].choices[1].description" "L" To iSuccess
Set ComAuthToken Of hoHttp To "ACCESS_TOKEN"
Get Create (RefClass(cComChilkatHttpResponse)) To hoResp
If (Not(IsComObjectCreated(hoResp))) Begin
Send CreateComObject of hoResp
End
Get pvComObject of hoJson to vJson
Get pvComObject of hoResp to vResp
Get ComHttpJson Of hoHttp "POST" "https://www.wixapis.com/stores/v1/products" vJson "application/json" vResp To iSuccess
If (iSuccess = False) Begin
Get ComLastErrorText Of hoHttp To sTemp1
Showln sTemp1
Procedure_Return
End
Get Create (RefClass(cComChilkatStringBuilder)) To hoSbResponseBody
If (Not(IsComObjectCreated(hoSbResponseBody))) Begin
Send CreateComObject of hoSbResponseBody
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComGetBodySb Of hoResp vSbResponseBody To iSuccess
Get Create (RefClass(cComChilkatJsonObject)) To hoJResp
If (Not(IsComObjectCreated(hoJResp))) Begin
Send CreateComObject of hoJResp
End
Get pvComObject of hoSbResponseBody to vSbResponseBody
Get ComLoadSb Of hoJResp vSbResponseBody To iSuccess
Set ComEmitCompact Of hoJResp To False
Showln "Response Body:"
Get ComEmit Of hoJResp To sTemp1
Showln sTemp1
Get ComStatusCode Of hoResp To iRespStatusCode
Showln "Response Status Code = " iRespStatusCode
If (iRespStatusCode >= 400) Begin
Showln "Response Header:"
Get ComHeader Of hoResp To sTemp1
Showln sTemp1
Showln "Failed."
Procedure_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
Get ComStringOf Of hoJResp "product.id" To sProductId
Get ComStringOf Of hoJResp "product.name" To sProductName
Get ComStringOf Of hoJResp "product.slug" To sProductSlug
Get ComBoolOf Of hoJResp "product.visible" To iProductVisible
Get ComStringOf Of hoJResp "product.productType" To sProductProductType
Get ComStringOf Of hoJResp "product.description" To sProductDescription
Get ComBoolOf Of hoJResp "product.stock.trackInventory" To iProductStockTrackInventory
Get ComBoolOf Of hoJResp "product.stock.inStock" To iProductStockInStock
Get ComStringOf Of hoJResp "product.price.currency" To sProductPriceCurrency
Get ComStringOf Of hoJResp "product.price.price" To sProductPricePrice
Get ComStringOf Of hoJResp "product.price.discountedPrice" To sProductPriceDiscountedPrice
Get ComStringOf Of hoJResp "product.price.formatted.price" To sProductPriceFormattedPrice
Get ComStringOf Of hoJResp "product.price.formatted.discountedPrice" To sProductPriceFormattedDiscountedPrice
Get ComStringOf Of hoJResp "product.priceData.currency" To sProductPriceDataCurrency
Get ComStringOf Of hoJResp "product.priceData.price" To sProductPriceDataPrice
Get ComStringOf Of hoJResp "product.priceData.discountedPrice" To sProductPriceDataDiscountedPrice
Get ComStringOf Of hoJResp "product.priceData.formatted.price" To sProductPriceDataFormattedPrice
Get ComStringOf Of hoJResp "product.priceData.formatted.discountedPrice" To sProductPriceDataFormattedDiscountedPrice
Get ComBoolOf Of hoJResp "product.manageVariants" To iProductManageVariants
Get ComStringOf Of hoJResp "product.productPageUrl.base" To sProductProductPageUrlBase
Get ComStringOf Of hoJResp "product.productPageUrl.path" To sProductProductPageUrlPath
Get ComStringOf Of hoJResp "product.numericId" To sProductNumericId
Get ComStringOf Of hoJResp "product.inventoryItemId" To sProductInventoryItemId
Get ComStringOf Of hoJResp "product.discount.type" To sProductDiscountType
Get ComIntOf Of hoJResp "product.discount.value" To iProductDiscountValue
Move 0 To i
Get ComSizeOfArray Of hoJResp "product.additionalInfoSections" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "product.ribbons" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "product.media.items" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "product.customTextFields" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "product.productOptions" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "product.productOptions[i].optionType" To sOptionType
Get ComStringOf Of hoJResp "product.productOptions[i].name" To sName
Move 0 To j
Get ComSizeOfArray Of hoJResp "product.productOptions[i].choices" To iCount_j
While (j < iCount_j)
Set ComJ Of hoJResp To j
Get ComStringOf Of hoJResp "product.productOptions[i].choices[j].value" To sValue
Get ComStringOf Of hoJResp "product.productOptions[i].choices[j].description" To sDescription
Get ComBoolOf Of hoJResp "product.productOptions[i].choices[j].inStock" To iInStock
Get ComBoolOf Of hoJResp "product.productOptions[i].choices[j].visible" To iVisible
Move (j + 1) To j
Loop
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "product.collectionIds" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Move (i + 1) To i
Loop
Move 0 To i
Get ComSizeOfArray Of hoJResp "product.variants" To iCount_i
While (i < iCount_i)
Set ComI Of hoJResp To i
Get ComStringOf Of hoJResp "product.variants[i].id" To sId
Get ComStringOf Of hoJResp "product.variants[i].choices.Size" To sChoicesSize
Get ComStringOf Of hoJResp "product.variants[i].variant.priceData.currency" To sVariantPriceDataCurrency
Get ComStringOf Of hoJResp "product.variants[i].variant.priceData.price" To sVariantPriceDataPrice
Get ComStringOf Of hoJResp "product.variants[i].variant.priceData.discountedPrice" To sVariantPriceDataDiscountedPrice
Get ComStringOf Of hoJResp "product.variants[i].variant.priceData.formatted.price" To sVariantPriceDataFormattedPrice
Get ComStringOf Of hoJResp "product.variants[i].variant.priceData.formatted.discountedPrice" To sVariantPriceDataFormattedDiscountedPrice
Get ComIntOf Of hoJResp "product.variants[i].variant.weight" To iVariantWeight
Get ComBoolOf Of hoJResp "product.variants[i].variant.visible" To iVariantVisible
Move (i + 1) To i
Loop
End_Procedure