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) Walmart - Get an Order by purchaseOrderIdGets the XML data for an order by purchaseOrderId. Note: This example requires Chilkat v9.5.0.67 or greater.
#include <C_CkStringBuilderW.h> #include <C_CkAuthUtilW.h> #include <C_CkJsonObjectW.h> #include <C_CkHttpW.h> #include <C_CkXmlW.h> void ChilkatSample(void) { HCkStringBuilderW sbUrl; BOOL success; int numReplaced; const wchar_t *requestMethod; HCkAuthUtilW authUtil; const wchar_t *wmConsumerId; const wchar_t *wmPrivateKey; const wchar_t *jsonStr; HCkJsonObjectW json; HCkHttpW http; const wchar_t *xmlStr; HCkXmlW xml; // This example requires the Chilkat API to have been previously unlocked. // See Global Unlock Sample for sample code. // Demonstrates how to get the XML for a particular order by purchaseOrderId // Sends the following GET request: // GET https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId} sbUrl = CkStringBuilderW_Create(); success = CkStringBuilderW_Append(sbUrl,L"https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}"); numReplaced = CkStringBuilderW_Replace(sbUrl,L"{purchaseOrderId}",L"1111691995111"); requestMethod = L"GET"; // First we need to generate a signature for the request. // The signature needs to be re-generated for each new Walmart HTTP request. authUtil = CkAuthUtilW_Create(); wmConsumerId = L"WALMART_CONSUMER_ID"; wmPrivateKey = L"WALMART_PRIVATE_KEY"; jsonStr = CkAuthUtilW_walmartSignature(authUtil,CkStringBuilderW_getAsString(sbUrl),wmConsumerId,wmPrivateKey,requestMethod); if (CkAuthUtilW_getLastMethodSuccess(authUtil) != TRUE) { wprintf(L"%s\n",CkAuthUtilW_lastErrorText(authUtil)); CkStringBuilderW_Dispose(sbUrl); CkAuthUtilW_Dispose(authUtil); 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 json = CkJsonObjectW_Create(); CkJsonObjectW_Load(json,jsonStr); http = CkHttpW_Create(); CkHttpW_SetRequestHeader(http,L"WM_SVC.NAME",L"Walmart Marketplace"); CkHttpW_SetRequestHeader(http,L"WM_QOS.CORRELATION_ID",CkJsonObjectW_stringOf(json,L"correlation_id")); CkHttpW_SetRequestHeader(http,L"WM_SEC.TIMESTAMP",CkJsonObjectW_stringOf(json,L"timestamp")); CkHttpW_SetRequestHeader(http,L"WM_SEC.AUTH_SIGNATURE",CkJsonObjectW_stringOf(json,L"signature")); CkHttpW_SetRequestHeader(http,L"WM_CONSUMER.ID",wmConsumerId); CkHttpW_SetRequestHeader(http,L"WM_CONSUMER.CHANNEL.TYPE",L"WALMART_CHANNEL_TYPE"); CkHttpW_putAccept(http,L"application/xml"); // Note: Do not explicitly set the "Host" header. Chilkat will set it automatically. xmlStr = CkHttpW_quickGetStr(http,CkStringBuilderW_getAsString(sbUrl)); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkStringBuilderW_Dispose(sbUrl); CkAuthUtilW_Dispose(authUtil); CkJsonObjectW_Dispose(json); CkHttpW_Dispose(http); return; } xml = CkXmlW_Create(); CkXmlW_LoadXml(xml,xmlStr); // A successful response should have a 200 response status if (CkHttpW_getLastStatus(http) != 200) { wprintf(L"%s\n",CkXmlW_getXml(xml)); wprintf(L"Response Status Code: %d\n",CkHttpW_getLastStatus(http)); wprintf(L"Failed.\n"); CkStringBuilderW_Dispose(sbUrl); CkAuthUtilW_Dispose(authUtil); CkJsonObjectW_Dispose(json); CkHttpW_Dispose(http); CkXmlW_Dispose(xml); return; } // Show the XML response: wprintf(L"%s\n",CkXmlW_getXml(xml)); wprintf(L"Success.\n"); CkStringBuilderW_Dispose(sbUrl); CkAuthUtilW_Dispose(authUtil); CkJsonObjectW_Dispose(json); CkHttpW_Dispose(http); CkXmlW_Dispose(xml); } |
© 2000-2023 Chilkat Software, Inc. All Rights Reserved.