Xbase++
Xbase++
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 Xbase++ Downloads
LOCAL nSuccess
LOCAL oHttp
LOCAL oJson
LOCAL oResp
LOCAL oSbResponseBody
LOCAL oJResp
LOCAL nRespStatusCode
LOCAL cOptionType
LOCAL cName
LOCAL j
LOCAL nCount_j
LOCAL cValue
LOCAL cDescription
LOCAL nInStock
LOCAL nVisible
LOCAL cId
LOCAL cChoicesSize
LOCAL cVariantPriceDataCurrency
LOCAL cVariantPriceDataPrice
LOCAL cVariantPriceDataDiscountedPrice
LOCAL cVariantPriceDataFormattedPrice
LOCAL cVariantPriceDataFormattedDiscountedPrice
LOCAL nVariantWeight
LOCAL nVariantVisible
LOCAL cProductId
LOCAL cProductName
LOCAL cProductSlug
LOCAL nProductVisible
LOCAL cProductProductType
LOCAL cProductDescription
LOCAL nProductStockTrackInventory
LOCAL nProductStockInStock
LOCAL cProductPriceCurrency
LOCAL cProductPricePrice
LOCAL cProductPriceDiscountedPrice
LOCAL cProductPriceFormattedPrice
LOCAL cProductPriceFormattedDiscountedPrice
LOCAL cProductPriceDataCurrency
LOCAL cProductPriceDataPrice
LOCAL cProductPriceDataDiscountedPrice
LOCAL cProductPriceDataFormattedPrice
LOCAL cProductPriceDataFormattedDiscountedPrice
LOCAL nProductManageVariants
LOCAL cProductProductPageUrlBase
LOCAL cProductProductPageUrlPath
LOCAL cProductNumericId
LOCAL cProductInventoryItemId
LOCAL cProductDiscountType
LOCAL nProductDiscountValue
LOCAL i
LOCAL nCount_i
nSuccess := 0
// This example assumes the Chilkat API to have been previously unlocked.
// See Global Unlock Sample for sample code.
oHttp := CreateObject("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 := CreateObject("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", 0)
oJson:UpdateNumber("product.weight", "0.2")
oJson:UpdateString("product.discount.type", "AMOUNT")
oJson:UpdateInt("product.discount.value", 1)
oJson:UpdateBool("product.manageVariants", 1)
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 := CreateObject("Chilkat.HttpResponse")
nSuccess := oHttp:HttpJson("POST", "https://www.wixapis.com/stores/v1/products", oJson, "application/json", oResp)
IF (nSuccess == 0)
? oHttp:LastErrorText
oHttp:destroy()
oJson:destroy()
oResp:destroy()
RETURN
ENDIF
oSbResponseBody := CreateObject("Chilkat.StringBuilder")
oResp:GetBodySb(oSbResponseBody)
oJResp := CreateObject("Chilkat.JsonObject")
oJResp:LoadSb(oSbResponseBody)
oJResp:EmitCompact := 0
? "Response Body:"
? oJResp:Emit()
nRespStatusCode := oResp:StatusCode
? "Response Status Code = " + Str(nRespStatusCode)
IF (nRespStatusCode >= 400)
? "Response Header:"
? oResp:Header
? "Failed."
oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()
RETURN
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
cProductId := oJResp:StringOf("product.id")
cProductName := oJResp:StringOf("product.name")
cProductSlug := oJResp:StringOf("product.slug")
nProductVisible := oJResp:BoolOf("product.visible")
cProductProductType := oJResp:StringOf("product.productType")
cProductDescription := oJResp:StringOf("product.description")
nProductStockTrackInventory := oJResp:BoolOf("product.stock.trackInventory")
nProductStockInStock := oJResp:BoolOf("product.stock.inStock")
cProductPriceCurrency := oJResp:StringOf("product.price.currency")
cProductPricePrice := oJResp:StringOf("product.price.price")
cProductPriceDiscountedPrice := oJResp:StringOf("product.price.discountedPrice")
cProductPriceFormattedPrice := oJResp:StringOf("product.price.formatted.price")
cProductPriceFormattedDiscountedPrice := oJResp:StringOf("product.price.formatted.discountedPrice")
cProductPriceDataCurrency := oJResp:StringOf("product.priceData.currency")
cProductPriceDataPrice := oJResp:StringOf("product.priceData.price")
cProductPriceDataDiscountedPrice := oJResp:StringOf("product.priceData.discountedPrice")
cProductPriceDataFormattedPrice := oJResp:StringOf("product.priceData.formatted.price")
cProductPriceDataFormattedDiscountedPrice := oJResp:StringOf("product.priceData.formatted.discountedPrice")
nProductManageVariants := oJResp:BoolOf("product.manageVariants")
cProductProductPageUrlBase := oJResp:StringOf("product.productPageUrl.base")
cProductProductPageUrlPath := oJResp:StringOf("product.productPageUrl.path")
cProductNumericId := oJResp:StringOf("product.numericId")
cProductInventoryItemId := oJResp:StringOf("product.inventoryItemId")
cProductDiscountType := oJResp:StringOf("product.discount.type")
nProductDiscountValue := oJResp:IntOf("product.discount.value")
i := 0
nCount_i := oJResp:SizeOfArray("product.additionalInfoSections")
DO WHILE i < nCount_i
oJResp:I := i
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("product.ribbons")
DO WHILE i < nCount_i
oJResp:I := i
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("product.media.items")
DO WHILE i < nCount_i
oJResp:I := i
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("product.customTextFields")
DO WHILE i < nCount_i
oJResp:I := i
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("product.productOptions")
DO WHILE i < nCount_i
oJResp:I := i
cOptionType := oJResp:StringOf("product.productOptions[i].optionType")
cName := oJResp:StringOf("product.productOptions[i].name")
j := 0
nCount_j := oJResp:SizeOfArray("product.productOptions[i].choices")
DO WHILE j < nCount_j
oJResp:J := j
cValue := oJResp:StringOf("product.productOptions[i].choices[j].value")
cDescription := oJResp:StringOf("product.productOptions[i].choices[j].description")
nInStock := oJResp:BoolOf("product.productOptions[i].choices[j].inStock")
nVisible := oJResp:BoolOf("product.productOptions[i].choices[j].visible")
j := j + 1
ENDDO
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("product.collectionIds")
DO WHILE i < nCount_i
oJResp:I := i
i := i + 1
ENDDO
i := 0
nCount_i := oJResp:SizeOfArray("product.variants")
DO WHILE i < nCount_i
oJResp:I := i
cId := oJResp:StringOf("product.variants[i].id")
cChoicesSize := oJResp:StringOf("product.variants[i].choices.Size")
cVariantPriceDataCurrency := oJResp:StringOf("product.variants[i].variant.priceData.currency")
cVariantPriceDataPrice := oJResp:StringOf("product.variants[i].variant.priceData.price")
cVariantPriceDataDiscountedPrice := oJResp:StringOf("product.variants[i].variant.priceData.discountedPrice")
cVariantPriceDataFormattedPrice := oJResp:StringOf("product.variants[i].variant.priceData.formatted.price")
cVariantPriceDataFormattedDiscountedPrice := oJResp:StringOf("product.variants[i].variant.priceData.formatted.discountedPrice")
nVariantWeight := oJResp:IntOf("product.variants[i].variant.weight")
nVariantVisible := oJResp:BoolOf("product.variants[i].variant.visible")
i := i + 1
ENDDO
oHttp:destroy()
oJson:destroy()
oResp:destroy()
oSbResponseBody:destroy()
oJResp:destroy()