Chilkat HOME Android™ Classic ASP C C++ C# Mono C# .NET Core C# C# UWP/WinRT DataFlex Delphi ActiveX Delphi DLL Visual FoxPro Java Lianja MFC Objective-C Perl PHP ActiveX PHP Extension PowerBuilder PowerShell PureBasic CkPython Chilkat2-Python Ruby SQL Server Swift 2 Swift 3,4,5... Tcl Unicode C Unicode C++ Visual Basic 6.0 VB.NET VB.NET UWP/WinRT VBScript Xojo Plugin Node.js Excel Go
(MFC) 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 <CkHttp.h> #include <CkStringBuilder.h> #include <CkJsonObject.h> void ChilkatSample(void) { CkString strOut; // This example assumes the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. CkHttp http; bool success; // Implements the following CURL command: // curl -X GET \ // https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING CkStringBuilder sbResponseBody; success = http.QuickGetSb("https://openapi.etsy.com/v2/listings/listing_id/inventory?api_key=MY_ETSY_KEYSTRING",sbResponseBody); if (success == false) { strOut.append(http.lastErrorText()); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); return; } CkJsonObject jResp; jResp.LoadSb(sbResponseBody); jResp.put_EmitCompact(false); strOut.append("Response Body:"); strOut.append("\r\n"); strOut.append(jResp.emit()); strOut.append("\r\n"); int respStatusCode = http.get_LastStatus(); strOut.append("Response Status Code = "); strOut.appendInt(respStatusCode); strOut.append("\r\n"); if (respStatusCode >= 400) { strOut.append("Response Header:"); strOut.append("\r\n"); strOut.append(http.lastHeader()); strOut.append("\r\n"); strOut.append("Failed."); strOut.append("\r\n"); SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); 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. int product_id; int j; int count_j; int offering_id; int priceAmount; int priceDivisor; const char *priceCurrency_code = 0; const char *priceCurrency_formatted_short = 0; const char *priceCurrency_formatted_long = 0; const char *priceCurrency_formatted_raw = 0; int quantity; int count = jResp.IntOf("count"); const char *paramsListing_id = jResp.stringOf("params.listing_id"); bool paramsWrite_missing_inventory = jResp.BoolOf("params.write_missing_inventory"); const char *v_type = jResp.stringOf("type"); int i = 0; int count_i = jResp.SizeOfArray("results.products"); while (i < count_i) { jResp.put_I(i); product_id = jResp.IntOf("results.products[i].product_id"); j = 0; count_j = jResp.SizeOfArray("results.products[i].property_values"); while (j < count_j) { jResp.put_J(j); j = j + 1; } j = 0; count_j = jResp.SizeOfArray("results.products[i].offerings"); while (j < count_j) { jResp.put_J(j); offering_id = jResp.IntOf("results.products[i].offerings[j].offering_id"); priceAmount = jResp.IntOf("results.products[i].offerings[j].price.amount"); priceDivisor = jResp.IntOf("results.products[i].offerings[j].price.divisor"); priceCurrency_code = jResp.stringOf("results.products[i].offerings[j].price.currency_code"); priceCurrency_formatted_short = jResp.stringOf("results.products[i].offerings[j].price.currency_formatted_short"); priceCurrency_formatted_long = jResp.stringOf("results.products[i].offerings[j].price.currency_formatted_long"); priceCurrency_formatted_raw = jResp.stringOf("results.products[i].offerings[j].price.currency_formatted_raw"); quantity = jResp.IntOf("results.products[i].offerings[j].quantity"); j = j + 1; } i = i + 1; } SetDlgItemText(IDC_EDIT1,strOut.getUnicode()); } |
© 2000-2022 Chilkat Software, Inc. All Rights Reserved.