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) Etsy: Get the Inventory for a ListingGets the inventory for a listing. For more information, see https://www.etsy.com/developers/documentation/reference/listinginventory
#include <C_CkHttpW.h> #include <C_CkStringBuilderW.h> #include <C_CkJsonObjectW.h> void ChilkatSample(void) { HCkHttpW http; BOOL success; HCkStringBuilderW sbResponseBody; HCkJsonObjectW jResp; int respStatusCode; int product_id; int j; int count_j; int offering_id; int priceAmount; int priceDivisor; const wchar_t *priceCurrency_code; const wchar_t *priceCurrency_formatted_short; const wchar_t *priceCurrency_formatted_long; const wchar_t *priceCurrency_formatted_raw; int quantity; int count; const wchar_t *paramsListing_id; BOOL paramsWrite_missing_inventory; const wchar_t *v_type; 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 GET \ // https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING sbResponseBody = CkStringBuilderW_Create(); success = CkHttpW_QuickGetSb(http,L"https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING",sbResponseBody); if (success == FALSE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); return; } jResp = CkJsonObjectW_Create(); CkJsonObjectW_LoadSb(jResp,sbResponseBody); CkJsonObjectW_putEmitCompact(jResp,FALSE); wprintf(L"Response Body:\n"); wprintf(L"%s\n",CkJsonObjectW_emit(jResp)); respStatusCode = CkHttpW_getLastStatus(http); wprintf(L"Response Status Code = %d\n",respStatusCode); if (respStatusCode >= 400) { wprintf(L"Response Header:\n"); wprintf(L"%s\n",CkHttpW_lastHeader(http)); wprintf(L"Failed.\n"); CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); return; } // Sample JSON response: // (Sample code for parsing the JSON response is shown below) // { // "count": 1, // "results": { // "products": [ // { // "product_id": 3361120103, // "property_values": [ // ], // "offerings": [ // { // "offering_id": 3579642570, // "price": { // "amount": 16000, // "divisor": 100, // "currency_code": "USD", // "currency_formatted_short": "$160.00", // "currency_formatted_long": "$160.00 USD", // "currency_formatted_raw": "160.00" // }, // "quantity": 1 // } // ] // } // ] // }, // "params": { // "listing_id": "720138253", // "write_missing_inventory": false // }, // "type": "ListingInventory", // "pagination": {} // } // 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. count = CkJsonObjectW_IntOf(jResp,L"count"); paramsListing_id = CkJsonObjectW_stringOf(jResp,L"params.listing_id"); paramsWrite_missing_inventory = CkJsonObjectW_BoolOf(jResp,L"params.write_missing_inventory"); v_type = CkJsonObjectW_stringOf(jResp,L"type"); i = 0; count_i = CkJsonObjectW_SizeOfArray(jResp,L"results.products"); while (i < count_i) { CkJsonObjectW_putI(jResp,i); product_id = CkJsonObjectW_IntOf(jResp,L"results.products[i].product_id"); j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"results.products[i].property_values"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); j = j + 1; } j = 0; count_j = CkJsonObjectW_SizeOfArray(jResp,L"results.products[i].offerings"); while (j < count_j) { CkJsonObjectW_putJ(jResp,j); offering_id = CkJsonObjectW_IntOf(jResp,L"results.products[i].offerings[j].offering_id"); priceAmount = CkJsonObjectW_IntOf(jResp,L"results.products[i].offerings[j].price.amount"); priceDivisor = CkJsonObjectW_IntOf(jResp,L"results.products[i].offerings[j].price.divisor"); priceCurrency_code = CkJsonObjectW_stringOf(jResp,L"results.products[i].offerings[j].price.currency_code"); priceCurrency_formatted_short = CkJsonObjectW_stringOf(jResp,L"results.products[i].offerings[j].price.currency_formatted_short"); priceCurrency_formatted_long = CkJsonObjectW_stringOf(jResp,L"results.products[i].offerings[j].price.currency_formatted_long"); priceCurrency_formatted_raw = CkJsonObjectW_stringOf(jResp,L"results.products[i].offerings[j].price.currency_formatted_raw"); quantity = CkJsonObjectW_IntOf(jResp,L"results.products[i].offerings[j].quantity"); j = j + 1; } i = i + 1; } CkHttpW_Dispose(http); CkStringBuilderW_Dispose(sbResponseBody); CkJsonObjectW_Dispose(jResp); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.