Sample code for 30+ languages & platforms
PowerBuilder

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

PowerBuilder
integer li_rc
long li_Success
oleobject loo_Http
oleobject loo_Json
oleobject loo_Resp
oleobject loo_SbResponseBody
oleobject loo_JResp
long li_RespStatusCode
string ls_OptionType
string ls_Name
long j
long li_Count_j
string ls_Value
string ls_Description
long li_InStock
long li_Visible
string ls_Id
string ls_ChoicesSize
string ls_VariantPriceDataCurrency
string ls_VariantPriceDataPrice
string ls_VariantPriceDataDiscountedPrice
string ls_VariantPriceDataFormattedPrice
string ls_VariantPriceDataFormattedDiscountedPrice
long li_VariantWeight
long li_VariantVisible
string ls_ProductId
string ls_ProductName
string ls_ProductSlug
long li_ProductVisible
string ls_ProductProductType
string ls_ProductDescription
long li_ProductStockTrackInventory
long li_ProductStockInStock
string ls_ProductPriceCurrency
string ls_ProductPricePrice
string ls_ProductPriceDiscountedPrice
string ls_ProductPriceFormattedPrice
string ls_ProductPriceFormattedDiscountedPrice
string ls_ProductPriceDataCurrency
string ls_ProductPriceDataPrice
string ls_ProductPriceDataDiscountedPrice
string ls_ProductPriceDataFormattedPrice
string ls_ProductPriceDataFormattedDiscountedPrice
long li_ProductManageVariants
string ls_ProductProductPageUrlBase
string ls_ProductProductPageUrlPath
string ls_ProductNumericId
string ls_ProductInventoryItemId
string ls_ProductDiscountType
long li_ProductDiscountValue
long i
long li_Count_i

li_Success = 0

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

loo_Http = create oleobject
li_rc = loo_Http.ConnectToNewObject("Chilkat.Http")
if li_rc < 0 then
    destroy loo_Http
    MessageBox("Error","Connecting to COM object failed")
    return
end if

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

loo_Json = create oleobject
li_rc = loo_Json.ConnectToNewObject("Chilkat.JsonObject")

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

loo_Http.AuthToken = "ACCESS_TOKEN"

loo_Resp = create oleobject
li_rc = loo_Resp.ConnectToNewObject("Chilkat.HttpResponse")

li_Success = loo_Http.HttpJson("POST","https://www.wixapis.com/stores/v1/products",loo_Json,"application/json",loo_Resp)
if li_Success = 0 then
    Write-Debug loo_Http.LastErrorText
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    return
end if

loo_SbResponseBody = create oleobject
li_rc = loo_SbResponseBody.ConnectToNewObject("Chilkat.StringBuilder")

loo_Resp.GetBodySb(loo_SbResponseBody)
loo_JResp = create oleobject
li_rc = loo_JResp.ConnectToNewObject("Chilkat.JsonObject")

loo_JResp.LoadSb(loo_SbResponseBody)
loo_JResp.EmitCompact = 0

Write-Debug "Response Body:"
Write-Debug loo_JResp.Emit()

li_RespStatusCode = loo_Resp.StatusCode
Write-Debug "Response Status Code = " + string(li_RespStatusCode)
if li_RespStatusCode >= 400 then
    Write-Debug "Response Header:"
    Write-Debug loo_Resp.Header
    Write-Debug "Failed."
    destroy loo_Http
    destroy loo_Json
    destroy loo_Resp
    destroy loo_SbResponseBody
    destroy loo_JResp
    return
end if

//  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

ls_ProductId = loo_JResp.StringOf("product.id")
ls_ProductName = loo_JResp.StringOf("product.name")
ls_ProductSlug = loo_JResp.StringOf("product.slug")
li_ProductVisible = loo_JResp.BoolOf("product.visible")
ls_ProductProductType = loo_JResp.StringOf("product.productType")
ls_ProductDescription = loo_JResp.StringOf("product.description")
li_ProductStockTrackInventory = loo_JResp.BoolOf("product.stock.trackInventory")
li_ProductStockInStock = loo_JResp.BoolOf("product.stock.inStock")
ls_ProductPriceCurrency = loo_JResp.StringOf("product.price.currency")
ls_ProductPricePrice = loo_JResp.StringOf("product.price.price")
ls_ProductPriceDiscountedPrice = loo_JResp.StringOf("product.price.discountedPrice")
ls_ProductPriceFormattedPrice = loo_JResp.StringOf("product.price.formatted.price")
ls_ProductPriceFormattedDiscountedPrice = loo_JResp.StringOf("product.price.formatted.discountedPrice")
ls_ProductPriceDataCurrency = loo_JResp.StringOf("product.priceData.currency")
ls_ProductPriceDataPrice = loo_JResp.StringOf("product.priceData.price")
ls_ProductPriceDataDiscountedPrice = loo_JResp.StringOf("product.priceData.discountedPrice")
ls_ProductPriceDataFormattedPrice = loo_JResp.StringOf("product.priceData.formatted.price")
ls_ProductPriceDataFormattedDiscountedPrice = loo_JResp.StringOf("product.priceData.formatted.discountedPrice")
li_ProductManageVariants = loo_JResp.BoolOf("product.manageVariants")
ls_ProductProductPageUrlBase = loo_JResp.StringOf("product.productPageUrl.base")
ls_ProductProductPageUrlPath = loo_JResp.StringOf("product.productPageUrl.path")
ls_ProductNumericId = loo_JResp.StringOf("product.numericId")
ls_ProductInventoryItemId = loo_JResp.StringOf("product.inventoryItemId")
ls_ProductDiscountType = loo_JResp.StringOf("product.discount.type")
li_ProductDiscountValue = loo_JResp.IntOf("product.discount.value")
i = 0
li_Count_i = loo_JResp.SizeOfArray("product.additionalInfoSections")
do while i < li_Count_i
    loo_JResp.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("product.ribbons")
do while i < li_Count_i
    loo_JResp.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("product.media.items")
do while i < li_Count_i
    loo_JResp.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("product.customTextFields")
do while i < li_Count_i
    loo_JResp.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("product.productOptions")
do while i < li_Count_i
    loo_JResp.I = i
    ls_OptionType = loo_JResp.StringOf("product.productOptions[i].optionType")
    ls_Name = loo_JResp.StringOf("product.productOptions[i].name")
    j = 0
    li_Count_j = loo_JResp.SizeOfArray("product.productOptions[i].choices")
    do while j < li_Count_j
        loo_JResp.J = j
        ls_Value = loo_JResp.StringOf("product.productOptions[i].choices[j].value")
        ls_Description = loo_JResp.StringOf("product.productOptions[i].choices[j].description")
        li_InStock = loo_JResp.BoolOf("product.productOptions[i].choices[j].inStock")
        li_Visible = loo_JResp.BoolOf("product.productOptions[i].choices[j].visible")
        j = j + 1
    loop
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("product.collectionIds")
do while i < li_Count_i
    loo_JResp.I = i
    i = i + 1
loop
i = 0
li_Count_i = loo_JResp.SizeOfArray("product.variants")
do while i < li_Count_i
    loo_JResp.I = i
    ls_Id = loo_JResp.StringOf("product.variants[i].id")
    ls_ChoicesSize = loo_JResp.StringOf("product.variants[i].choices.Size")
    ls_VariantPriceDataCurrency = loo_JResp.StringOf("product.variants[i].variant.priceData.currency")
    ls_VariantPriceDataPrice = loo_JResp.StringOf("product.variants[i].variant.priceData.price")
    ls_VariantPriceDataDiscountedPrice = loo_JResp.StringOf("product.variants[i].variant.priceData.discountedPrice")
    ls_VariantPriceDataFormattedPrice = loo_JResp.StringOf("product.variants[i].variant.priceData.formatted.price")
    ls_VariantPriceDataFormattedDiscountedPrice = loo_JResp.StringOf("product.variants[i].variant.priceData.formatted.discountedPrice")
    li_VariantWeight = loo_JResp.IntOf("product.variants[i].variant.weight")
    li_VariantVisible = loo_JResp.BoolOf("product.variants[i].variant.visible")
    i = i + 1
loop


destroy loo_Http
destroy loo_Json
destroy loo_Resp
destroy loo_SbResponseBody
destroy loo_JResp