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 - Get all Products in a StoreGets the first page of products in a store. For more information, see https://dev.wix.com/api/rest/wix-stores/catalog/filter-and-sort
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 -H "Content-Type: application/json" \ ; -d '{ ; "includeVariants": true ; }' https://www.wixapis.com/stores/v1/products/query json.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckUpdateBool(json,"includeVariants",1) CkHttp::setCkAuthToken(http, "ACCESS_TOKEN") CkHttp::ckSetRequestHeader(http,"Content-Type","application/json") resp.i = CkHttp::ckPostJson3(http,"https://www.wixapis.com/stores/v1/products/query","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) ; { ; "products": [ ; { ; "id": "58fcbb51-ff87-08ff-d97b-646726676e4a", ; "name": "webhook test", ; "slug": "webhook-test", ; "visible": true, ; "productType": "physical", ; "description": "<p>fasdf<\/p>", ; "stock": { ; "trackInventory": true, ; "quantity": 0, ; "inStock": false ; }, ; "price": { ; "currency": "ILS", ; "price": 234, ; "discountedPrice": 234, ; "formatted": { ; "price": "234.00 ", ; "discountedPrice": "234.00 " ; } ; }, ; "priceData": { ; "currency": "ILS", ; "price": 234, ; "discountedPrice": 234, ; "formatted": { ; "price": "234.00 ", ; "discountedPrice": "234.00 " ; } ; }, ; "additionalInfoSections": [ ; ], ; "ribbons": [ ; { ; "text": "ribby" ; } ; ], ; "media": { ; "items": [ ; ] ; }, ; "customTextFields": [ ; ], ; "manageVariants": true, ; "productOptions": [ ; ], ; "productPageUrl": { ; "base": "https://www.my-website.com/", ; "path": "/product-page/webhook-test" ; }, ; "numericId": "1567078000586000", ; "inventoryItemId": "a70344ae-0078-f700-2684-9b98d99891b5", ; "discount": { ; "type": "NONE", ; "value": 0 ; }, ; "collectionIds": [ ; ], ; "variants": [ ; ] ; }, ; { ; "id": "6507fd67-94e5-10af-73e4-d2167852d5bc", ; "name": "digital product", ; "slug": "digital-product", ; "visible": true, ; "productType": "digital", ; "description": "", ; "sku": "", ; "weight": 0, ; "stock": { ; "trackInventory": false, ; "inStock": true ; }, ; "price": { ; "currency": "ILS", ; "price": 123, ; "discountedPrice": 123, ; "formatted": { ; "price": "123.00 ", ; "discountedPrice": "123.00 " ; } ; }, ; "priceData": { ; "currency": "ILS", ; "price": 123, ; "discountedPrice": 123, ; "formatted": { ; "price": "123.00 ", ; "discountedPrice": "123.00 " ; } ; }, ; "additionalInfoSections": [ ; ], ; "ribbons": [ ; ], ; "media": { ; "items": [ ; ] ; }, ; "customTextFields": [ ; ], ; "manageVariants": false, ; "productOptions": [ ; ], ; "productPageUrl": { ; "base": "https://www.my-website.com/", ; "path": "/product-page/digital-product" ; }, ; "numericId": "1544009414325000", ; "inventoryItemId": "9af80298-6b1a-ef50-8c1b-2de987ad2a43", ; "discount": { ; "type": "NONE", ; "value": 0 ; }, ; "collectionIds": [ ; "ae886d55-2572-eee8-b2c4-13219844b5e4" ; ], ; "variants": [ ; ] ; } ; ], ; "metadata": { ; "items": 100, ; "offset": 0 ; }, ; "totalResults": 2 ; } ; Sample code for parsing the JSON response... ; Use the following online tool to generate parsing code from sample JSON: ; Generate Parsing Code from JSON id.s name.s slug.s visible.i productType.s description.s stockTrackInventory.i stockQuantity.i stockInStock.i priceCurrency.s pricePrice.i priceDiscountedPrice.i priceFormattedPrice.s priceFormattedDiscountedPrice.s priceDataCurrency.s priceDataPrice.i priceDataDiscountedPrice.i priceDataFormattedPrice.s priceDataFormattedDiscountedPrice.s manageVariants.i productPageUrlBase.s productPageUrlPath.s numericId.s inventoryItemId.s discountType.s discountValue.i sku.s weight.i j.i count_j.i text.s strVal.s metadataItems.i = CkJsonObject::ckIntOf(jResp,"metadata.items") metadataOffset.i = CkJsonObject::ckIntOf(jResp,"metadata.offset") totalResults.i = CkJsonObject::ckIntOf(jResp,"totalResults") i.i = 0 count_i.i = CkJsonObject::ckSizeOfArray(jResp,"products") While i < count_i CkJsonObject::setCkI(jResp, i) id = CkJsonObject::ckStringOf(jResp,"products[i].id") name = CkJsonObject::ckStringOf(jResp,"products[i].name") slug = CkJsonObject::ckStringOf(jResp,"products[i].slug") visible = CkJsonObject::ckBoolOf(jResp,"products[i].visible") productType = CkJsonObject::ckStringOf(jResp,"products[i].productType") description = CkJsonObject::ckStringOf(jResp,"products[i].description") stockTrackInventory = CkJsonObject::ckBoolOf(jResp,"products[i].stock.trackInventory") stockQuantity = CkJsonObject::ckIntOf(jResp,"products[i].stock.quantity") stockInStock = CkJsonObject::ckBoolOf(jResp,"products[i].stock.inStock") priceCurrency = CkJsonObject::ckStringOf(jResp,"products[i].price.currency") pricePrice = CkJsonObject::ckIntOf(jResp,"products[i].price.price") priceDiscountedPrice = CkJsonObject::ckIntOf(jResp,"products[i].price.discountedPrice") priceFormattedPrice = CkJsonObject::ckStringOf(jResp,"products[i].price.formatted.price") priceFormattedDiscountedPrice = CkJsonObject::ckStringOf(jResp,"products[i].price.formatted.discountedPrice") priceDataCurrency = CkJsonObject::ckStringOf(jResp,"products[i].priceData.currency") priceDataPrice = CkJsonObject::ckIntOf(jResp,"products[i].priceData.price") priceDataDiscountedPrice = CkJsonObject::ckIntOf(jResp,"products[i].priceData.discountedPrice") priceDataFormattedPrice = CkJsonObject::ckStringOf(jResp,"products[i].priceData.formatted.price") priceDataFormattedDiscountedPrice = CkJsonObject::ckStringOf(jResp,"products[i].priceData.formatted.discountedPrice") manageVariants = CkJsonObject::ckBoolOf(jResp,"products[i].manageVariants") productPageUrlBase = CkJsonObject::ckStringOf(jResp,"products[i].productPageUrl.base") productPageUrlPath = CkJsonObject::ckStringOf(jResp,"products[i].productPageUrl.path") numericId = CkJsonObject::ckStringOf(jResp,"products[i].numericId") inventoryItemId = CkJsonObject::ckStringOf(jResp,"products[i].inventoryItemId") discountType = CkJsonObject::ckStringOf(jResp,"products[i].discount.type") discountValue = CkJsonObject::ckIntOf(jResp,"products[i].discount.value") sku = CkJsonObject::ckStringOf(jResp,"products[i].sku") weight = CkJsonObject::ckIntOf(jResp,"products[i].weight") j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"products[i].additionalInfoSections") While j < count_j CkJsonObject::setCkJ(jResp, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"products[i].ribbons") While j < count_j CkJsonObject::setCkJ(jResp, j) text = CkJsonObject::ckStringOf(jResp,"products[i].ribbons[j].text") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"products[i].media.items") While j < count_j CkJsonObject::setCkJ(jResp, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"products[i].customTextFields") While j < count_j CkJsonObject::setCkJ(jResp, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"products[i].productOptions") While j < count_j CkJsonObject::setCkJ(jResp, j) j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"products[i].collectionIds") While j < count_j CkJsonObject::setCkJ(jResp, j) strVal = CkJsonObject::ckStringOf(jResp,"products[i].collectionIds[j]") j = j + 1 Wend j = 0 count_j = CkJsonObject::ckSizeOfArray(jResp,"products[i].variants") While j < count_j CkJsonObject::setCkJ(jResp, j) j = j + 1 Wend 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.