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
(Unicode C) 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
#include <C_CkHttpW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpResponseW.h> #include <C_CkStringBuilderW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkJsonObjectW json; HCkHttpResponseW resp; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; const wchar_t *id; const wchar_t *name; const wchar_t *slug; BOOL visible; const wchar_t *productType; const wchar_t *description; BOOL stockTrackInventory; int stockQuantity; BOOL stockInStock; const wchar_t *priceCurrency; int pricePrice; int priceDiscountedPrice; const wchar_t *priceFormattedPrice; const wchar_t *priceFormattedDiscountedPrice; const wchar_t *priceDataCurrency; int priceDataPrice; int priceDataDiscountedPrice; const wchar_t *priceDataFormattedPrice; const wchar_t *priceDataFormattedDiscountedPrice; BOOL manageVariants; const wchar_t *productPageUrlBase; const wchar_t *productPageUrlPath; const wchar_t *numericId; const wchar_t *inventoryItemId; const wchar_t *discountType; int discountValue; const wchar_t *sku; int weight; int j; int count_j; const wchar_t *text; const wchar_t *strVal; int metadataItems; int metadataOffset; int totalResults; int i; int count_i; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. http = CkHttpW_Create(); // 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 = CkJsonObjectW_Create(); CkJsonObjectW_UpdateBool(json,L"includeVariants",TRUE); CkHttpW_putAuthToken(http,L"ACCESS_TOKEN"); CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/json"); resp = CkHttpW_PostJson3(http,L"https://www.wixapis.com/stores/v1/products/query",L"application/json",json); if (CkHttpW_getLastMethodSuccess(http) == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); return; } sbResponseBody = CkStringBuilderW_Create(); CkHttpResponseW_GetBodySb(resp,sbResponseBody); jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpResponseW_getStatusCode(resp); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpResponseW_header(resp)); wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } CkHttpResponseW_Dispose(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 // Chilkat functions returning "const char *" return a pointer to temporary internal memory owned and managed by Chilkat. // See this example explaining how this memory should be used: const char * functions. metadataItems = CkJsonObjectW_IntOf(jResp,L"metadata.items"); metadataOffset = CkJsonObjectW_IntOf(jResp,L"metadata.offset"); totalResults = CkJsonObjectW_IntOf(jResp,L"totalResults"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"products"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); id = CkJsonObjectW_stringOf(jResp,L"products[i].id"); name = CkJsonObjectW_stringOf(jResp,L"products[i].name"); slug = CkJsonObjectW_stringOf(jResp,L"products[i].slug"); visible = CkJsonObjectW_BoolOf(jResp,L"products[i].visible"); productType = CkJsonObjectW_stringOf(jResp,L"products[i].productType"); description = CkJsonObjectW_stringOf(jResp,L"products[i].description"); stockTrackInventory = CkJsonObjectW_BoolOf(jResp,L"products[i].stock.trackInventory"); stockQuantity = CkJsonObjectW_IntOf(jResp,L"products[i].stock.quantity"); stockInStock = CkJsonObjectW_BoolOf(jResp,L"products[i].stock.inStock"); priceCurrency = CkJsonObjectW_stringOf(jResp,L"products[i].price.currency"); pricePrice = CkJsonObjectW_IntOf(jResp,L"products[i].price.price"); priceDiscountedPrice = CkJsonObjectW_IntOf(jResp,L"products[i].price.discountedPrice"); priceFormattedPrice = CkJsonObjectW_stringOf(jResp,L"products[i].price.formatted.price"); priceFormattedDiscountedPrice = CkJsonObjectW_stringOf(jResp,L"products[i].price.formatted.discountedPrice"); priceDataCurrency = CkJsonObjectW_stringOf(jResp,L"products[i].priceData.currency"); priceDataPrice = CkJsonObjectW_IntOf(jResp,L"products[i].priceData.price"); priceDataDiscountedPrice = CkJsonObjectW_IntOf(jResp,L"products[i].priceData.discountedPrice"); priceDataFormattedPrice = CkJsonObjectW_stringOf(jResp,L"products[i].priceData.formatted.price"); priceDataFormattedDiscountedPrice = CkJsonObjectW_stringOf(jResp,L"products[i].priceData.formatted.discountedPrice"); manageVariants = CkJsonObjectW_BoolOf(jResp,L"products[i].manageVariants"); productPageUrlBase = CkJsonObjectW_stringOf(jResp,L"products[i].productPageUrl.base"); productPageUrlPath = CkJsonObjectW_stringOf(jResp,L"products[i].productPageUrl.path"); numericId = CkJsonObjectW_stringOf(jResp,L"products[i].numericId"); inventoryItemId = CkJsonObjectW_stringOf(jResp,L"products[i].inventoryItemId"); discountType = CkJsonObjectW_stringOf(jResp,L"products[i].discount.type"); discountValue = CkJsonObjectW_IntOf(jResp,L"products[i].discount.value"); sku = CkJsonObjectW_stringOf(jResp,L"products[i].sku"); weight = CkJsonObjectW_IntOf(jResp,L"products[i].weight"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"products[i].additionalInfoSections"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"products[i].ribbons"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); text = CkJsonObjectW_stringOf(jResp,L"products[i].ribbons[j].text"); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"products[i].media.items"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"products[i].customTextFields"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"products[i].productOptions"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"products[i].collectionIds"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); strVal = CkJsonObjectW_stringOf(jResp,L"products[i].collectionIds[j]"); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"products[i].variants"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); j = j + 1; } i = i + 1; } CkHttpW_Dispose(http); CkJsonObjectW_Dispose(json); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.