![]() |
Chilkat HOME Android™ AutoIt C C# C++ Chilkat2-Python CkPython Classic ASP DataFlex Delphi DLL Go Java Node.js Objective-C PHP Extension Perl PowerBuilder PowerShell PureBasic Ruby SQL Server Swift Tcl Unicode C Unicode C++ VB.NET VBScript Visual Basic 6.0 Visual FoxPro Xojo Plugin
(Unicode C++) Walmart - Get Inventory for an ItemNote: This example uses classes, properties, or methods discontinued in Chilkat v11.0.0 or greater. Demonstrates how to get inventory for an item and parse the result.
#include <CkStringBuilderW.h> #include <CkAuthUtilW.h> #include <CkJsonObjectW.h> #include <CkHttpW.h> #include <CkXmlW.h> void ChilkatSample(void) { // --------------------------------------------------------------------------------------------------------- // Note: This example is deprecated. The Walmart API no longer uses the Signature method of authenticating. // Walmart now uses OAuth2. // --------------------------------------------------------------------------------------------------------- // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Sends the following GET request: // GET https://marketplace.walmartapis.com/v2/inventory?sku={SKU} CkStringBuilderW sbUrl; bool success = sbUrl.Append(L"https://marketplace.walmartapis.com/v2/inventory?sku={SKU}"); int numReplaced = sbUrl.Replace(L"{SKU}",L"HOPP~904~51041"); const wchar_t *requestMethod = L"GET"; // First we need to generate a signature for our request. // The signature needs to be re-generated for each new Walmart HTTP request. CkAuthUtilW authUtil; const wchar_t *wmConsumerId = L"WALMART_CONSUMER_ID"; const wchar_t *wmPrivateKey = L"WALMART_PRIVATE_KEY"; const wchar_t *jsonStr = authUtil.walmartSignature(sbUrl.getAsString(),wmConsumerId,wmPrivateKey,requestMethod); if (authUtil.get_LastMethodSuccess() != true) { wprintf(L"%s\n",authUtil.lastErrorText()); return; } // The JSON returned by WalmartSignature contains the values to be used in the following // header fields: WM_SEC.AUTH_SIGNATURE, WM_SEC.TIMESTAMP, and WM_QOS.CORRELATION_ID CkJsonObjectW json; json.Load(jsonStr); CkHttpW http; http.SetRequestHeader(L"WM_SVC.NAME",L"Walmart Marketplace"); http.SetRequestHeader(L"WM_QOS.CORRELATION_ID",json.stringOf(L"correlation_id")); http.SetRequestHeader(L"WM_SEC.TIMESTAMP",json.stringOf(L"timestamp")); http.SetRequestHeader(L"WM_SEC.AUTH_SIGNATURE",json.stringOf(L"signature")); http.SetRequestHeader(L"WM_CONSUMER.ID",wmConsumerId); http.put_Accept(L"application/xml"); // Note: Do not explicitly set the "Host" header. Chilkat will set it automatically. const wchar_t *xmlStr = http.quickGetStr(sbUrl.getAsString()); if (http.get_LastMethodSuccess() != true) { wprintf(L"%s\n",http.lastErrorText()); return; } CkXmlW xml; xml.LoadXml(xmlStr); // A successful response should have a 200 response status if (http.get_LastStatus() != 200) { wprintf(L"%s\n",xml.getXml()); wprintf(L"Response Status Code: %d\n",http.get_LastStatus()); wprintf(L"Failed.\n"); return; } // A sample XML response is shown below.. wprintf(L"%s\n",xml.getXml()); wprintf(L"--\n"); // To get the quantity: int quantity = xml.GetChildIntValue(L"quantity|amount"); wprintf(L"quantity = %d\n",quantity); // --------------------------------------- // Sample XML response // --------------------------------------- // <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> // <inventory xmlns="http://walmart.com/"> // <sku>HOPP~904~51041</sku> // <quantity> // <unit>EACH</unit> // <amount>234</amount> // </quantity> // <fulfillmentLagTime>5</fulfillmentLagTime> // </inventory> } |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.