Chilkat HOME .NET Core C# Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi ActiveX Delphi DLL Go Java Lianja Mono C# Node.js Objective-C PHP ActiveX PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(PureBasic) WiX Create ProductCreates a new product. Note: If you get a 403 error response, try refreshing the access token. For more information, see https://dev.wix.com/api/rest/wix-stores/catalog/product/create-product
IncludeFile "CkHttpResponse.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; This example assumes the Chilkat API to have been previously unlocked. ; See Global Unlock Sample for sample code. http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i ; 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" ; } ; ] ; } ; ] ; } ; } json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateString(json,"product.name","T-shirt") CkJsonObject::ckUpdateString(json,"product.productType","physical") CkJsonObject::ckUpdateNumber(json,"product.priceData.price","10.5") CkJsonObject::ckUpdateString(json,"product.description","nice summer t-shirt") CkJsonObject::ckUpdateString(json,"product.sku","123df") CkJsonObject::ckUpdateBool(json,"product.visible",0) CkJsonObject::ckUpdateNumber(json,"product.weight","0.2") CkJsonObject::ckUpdateString(json,"product.discount.type","AMOUNT") CkJsonObject::ckUpdateInt(json,"product.discount.value",1) CkJsonObject::ckUpdateBool(json,"product.manageVariants",1) CkJsonObject::ckUpdateString(json,"product.productOptions[0].name","Size") CkJsonObject::ckUpdateString(json,"product.productOptions[0].choices[0].value","S") CkJsonObject::ckUpdateString(json,"product.productOptions[0].choices[0].description","S") CkJsonObject::ckUpdateString(json,"product.productOptions[0].choices[1].value","L") CkJsonObject::ckUpdateString(json,"product.productOptions[0].choices[1].description","L") CkHttp::setCkAuthToken(http, "ACCESS_TOKEN") CkHttp::ckSetRequestHeader(http,"Content-Type","application/json") resp.i = CkHttp::ckPostJson3(http,"https://www.wixapis.com/stores/v1/products","application/json",json) If CkHttp::ckLastMethodSuccess(http) = 0 Debug CkHttp::ckLastErrorText(http) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) ProcedureReturn EndIf sbResponseBody.i = CkStringBuilder::ckCreate() If sbResponseBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttpResponse::ckGetBodySb(resp,sbResponseBody) jResp.i = CkJsonObject::ckCreate() If jResp.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoadSb(jResp,sbResponseBody) CkJsonObject::setCkEmitCompact(jResp, 0) Debug "Response Body:" Debug CkJsonObject::ckEmit(jResp) respStatusCode.i = CkHttpResponse::ckStatusCode(resp) Debug "Response Status Code = " + Str(respStatusCode) If respStatusCode >= 400 Debug "Response Header:" Debug CkHttpResponse::ckHeader(resp) Debug "Failed." CkHttpResponse::ckDispose(resp) CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; 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 optionType.s name.s j.i count_j.i value.s description.s inStock.i visible.i id.s choicesSize.s variantPriceDataCurrency.s variantPriceDataPrice.s variantPriceDataDiscountedPrice.s variantPriceDataFormattedPrice.s variantPriceDataFormattedDiscountedPrice.s variantWeight.i variantVisible.i productId.s = CkJsonObject::ckStringOf(jResp,"product.id") productName.s = CkJsonObject::ckStringOf(jResp,"product.name") productSlug.s = CkJsonObject::ckStringOf(jResp,"product.slug") productVisible.i = CkJsonObject::ckBoolOf(jResp,"product.visible") productProductType.s = CkJsonObject::ckStringOf(jResp,"product.productType") productDescription.s = CkJsonObject::ckStringOf(jResp,"product.description") productStockTrackInventory.i = CkJsonObject::ckBoolOf(jResp,"product.stock.trackInventory") productStockInStock.i = CkJsonObject::ckBoolOf(jResp,"product.stock.inStock") productPriceCurrency.s = CkJsonObject::ckStringOf(jResp,"product.price.currency") productPricePrice.s = CkJsonObject::ckStringOf(jResp,"product.price.price") productPriceDiscountedPrice.s = CkJsonObject::ckStringOf(jResp,"product.price.discountedPrice") productPriceFormattedPrice.s = CkJsonObject::ckStringOf(jResp,"product.price.formatted.price") productPriceFormattedDiscountedPrice.s = CkJsonObject::ckStringOf(jResp,"product.price.formatted.discountedPrice") productPriceDataCurrency.s = CkJsonObject::ckStringOf(jResp,"product.priceData.currency") productPriceDataPrice.s = CkJsonObject::ckStringOf(jResp,"product.priceData.price") productPriceDataDiscountedPrice.s = CkJsonObject::ckStringOf(jResp,"product.priceData.discountedPrice") productPriceDataFormattedPrice.s = CkJsonObject::ckStringOf(jResp,"product.priceData.formatted.price") productPriceDataFormattedDiscountedPrice.s = CkJsonObject::ckStringOf(jResp,"product.priceData.formatted.discountedPrice") productManageVariants.i = CkJsonObject::ckBoolOf(jResp,"product.manageVariants") productProductPageUrlBase.s = CkJsonObject::ckStringOf(jResp,"product.productPageUrl.base") productProductPageUrlPath.s = CkJsonObject::ckStringOf(jResp,"product.productPageUrl.path") productNumericId.s = CkJsonObject::ckStringOf(jResp,"product.numericId") productInventoryItemId.s = CkJsonObject::ckStringOf(jResp,"product.inventoryItemId") productDiscountType.s = CkJsonObject::ckStringOf(jResp,"product.discount.type") productDiscountValue.i = CkJsonObject::ckIntOf(jResp,"product.discount.value") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jResp,"product.additionalInfoSections") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"product.ribbons") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"product.media.items") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"product.customTextFields") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"product.productOptions") While i < count_i CkJsonObject::setCkI(jResp, i) optionType = CkJsonObject::ckStringOf(jResp,"product.productOptions[i].optionType") name = CkJsonObject::ckStringOf(jResp,"product.productOptions[i].name") j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"product.productOptions[i].choices") While j < count_j CkJsonObject::setCkJ(jResp, j) value = CkJsonObject::ckStringOf(jResp,"product.productOptions[i].choices[j].value") description = CkJsonObject::ckStringOf(jResp,"product.productOptions[i].choices[j].description") inStock = CkJsonObject::ckBoolOf(jResp,"product.productOptions[i].choices[j].inStock") visible = CkJsonObject::ckBoolOf(jResp,"product.productOptions[i].choices[j].visible") j = j + 1 Wend i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"product.collectionIds") While i < count_i CkJsonObject::setCkI(jResp, i) i = i + 1 Wend i = 0 count_i = CkJsonObject::ckSizeOfArray(jResp,"product.variants") While i < count_i CkJsonObject::setCkI(jResp, i) id = CkJsonObject::ckStringOf(jResp,"product.variants[i].id") choicesSize = CkJsonObject::ckStringOf(jResp,"product.variants[i].choices.Size") variantPriceDataCurrency = CkJsonObject::ckStringOf(jResp,"product.variants[i].variant.priceData.currency") variantPriceDataPrice = CkJsonObject::ckStringOf(jResp,"product.variants[i].variant.priceData.price") variantPriceDataDiscountedPrice = CkJsonObject::ckStringOf(jResp,"product.variants[i].variant.priceData.discountedPrice") variantPriceDataFormattedPrice = CkJsonObject::ckStringOf(jResp,"product.variants[i].variant.priceData.formatted.price") variantPriceDataFormattedDiscountedPrice = CkJsonObject::ckStringOf(jResp,"product.variants[i].variant.priceData.formatted.discountedPrice") variantWeight = CkJsonObject::ckIntOf(jResp,"product.variants[i].variant.weight") variantVisible = CkJsonObject::ckBoolOf(jResp,"product.variants[i].variant.visible") i = i + 1 Wend CkHttp::ckDispose(http) CkJsonObject::ckDispose(json) CkStringBuilder::ckDispose(sbResponseBody) CkJsonObject::ckDispose(jResp) ProcedureReturn EndProcedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.