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 - Send Shipping NotificationSee Shipping notifications/updates for more information about this call. 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_CkDateTimeW.h> #include <C_CkXmlW.h> #include <C_CkHttpResponseW.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; int lineNumber; const wchar_t *shippingStatus; int quantity; const wchar_t *carrier; const wchar_t *shippingMethod; const wchar_t *trackingNumber; HCkDateTimeW dtNow; const wchar_t *shipDateTime; HCkXmlW xmlBody; HCkXmlW orderLine; HCkXmlW orderLineStatus; HCkHttpResponseW resp; HCkXmlW xml; // --------------------------------------------------------------------------------------------------------- // 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 POST request: // POST https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}/shipping sbUrl = CkStringBuilderW_Create(); success = CkStringBuilderW_Append(sbUrl,L"https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}/shipping"); numReplaced = CkStringBuilderW_Replace(sbUrl,L"{purchaseOrderId}",L"1111691995111"); requestMethod = L"POST"; // First we need to generate a signature for our 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. // The body of the POST request will be XML that looks something like this: // <?xml version="1.0" encoding="UTF-8" standalone="yes"?> // <ns2:orderShipment // xmlns:ns2="http://walmart.com/mp/v3/orders" // xmlns:ns3="http://walmart.com/"> // <ns2:orderLines> // <ns2:orderLine> // <ns2:lineNumber>2</ns2:lineNumber> // <ns2:orderLineStatuses> // <ns2:orderLineStatus> // <ns2:status>Shipped</ns2:status> // <ns2:statusQuantity> // <ns2:unitOfMeasurement>Each</ns2:unitOfMeasurement> // <ns2:amount>1</ns2:amount> // </ns2:statusQuantity> // <ns2:trackingInfo> // <ns2:shipDateTime>2016-06-27T05:30:15.000Z</ns2:shipDateTime> // <ns2:carrierName> // <ns2:carrier>FedEx</ns2:carrier> // </ns2:carrierName> // <ns2:methodCode>Standard</ns2:methodCode> // <ns2:trackingNumber>12333634122</ns2:trackingNumber> // </ns2:trackingInfo> // </ns2:orderLineStatus> // </ns2:orderLineStatuses> // </ns2:orderLine> // </ns2:orderLines> // </ns2:orderShipment> // Build the XML request body: lineNumber = 1; shippingStatus = L"Shipped"; quantity = 1; carrier = L"USPS"; shippingMethod = L"Standard"; trackingNumber = L"9999869903501929298999"; dtNow = CkDateTimeW_Create(); CkDateTimeW_SetFromCurrentSystemTime(dtNow); shipDateTime = CkDateTimeW_getAsTimestamp(dtNow,FALSE); xmlBody = CkXmlW_Create(); CkXmlW_putTag(xmlBody,L"ns2:orderShipment"); CkXmlW_AddAttribute(xmlBody,L"xmlns:ns2",L"http://walmart.com/mp/v3/orders"); CkXmlW_AddAttribute(xmlBody,L"xmlns:ns3",L"http://walmart.com/"); CkXmlW_UpdateChildContentInt(xmlBody,L"ns2:orderLines|ns2:orderLine|ns2:lineNumber",lineNumber); orderLine = CkXmlW_GetChildWithTag(xmlBody,L"ns2:orderLines|ns2:orderLine"); CkXmlW_UpdateChildContent(orderLine,L"ns2:orderLineStatuses|ns2:orderLineStatus|ns2:status",shippingStatus); CkXmlW_Dispose(orderLine); orderLineStatus = CkXmlW_GetChildWithTag(orderLine,L"ns2:orderLineStatuses|ns2:orderLineStatus"); CkXmlW_UpdateChildContent(orderLineStatus,L"ns2:statusQuantity|ns2:unitOfMeasurement",L"Each"); CkXmlW_UpdateChildContentInt(orderLineStatus,L"ns2:statusQuantity|ns2:amount",quantity); CkXmlW_UpdateChildContent(orderLineStatus,L"ns2:trackingInfo|ns2:shipDateTime",shipDateTime); CkXmlW_UpdateChildContent(orderLineStatus,L"ns2:trackingInfo|ns2:carrierName|ns2:carrier",carrier); CkXmlW_UpdateChildContent(orderLineStatus,L"ns2:trackingInfo|ns2:methodCode",shippingMethod); CkXmlW_UpdateChildContent(orderLineStatus,L"ns2:trackingInfo|ns2:trackingNumber",trackingNumber); CkXmlW_Dispose(orderLineStatus); wprintf(L"POST request body:\n"); wprintf(L"%s\n",CkXmlW_getXml(xmlBody)); wprintf(L"--\n"); // This is a simple POST that can be sent w/ the PostXml method. // Explicitly set the Content-Type header, otherwise "text/xml" will be used. CkHttpW_SetRequestHeader(http,L"Content-Type",L"application/xml"); resp = CkHttpW_PostXml(http,CkStringBuilderW_getAsString(sbUrl),CkXmlW_getXml(xmlBody),L"utf-8"); if (CkHttpW_getLastMethodSuccess(http) != TRUE) { wprintf(L"%s\n",CkHttpW_lastErrorText(http)); CkStringBuilderW_Dispose(sbUrl); CkAuthUtilW_Dispose(authUtil); CkJsonObjectW_Dispose(json); CkHttpW_Dispose(http); CkDateTimeW_Dispose(dtNow); CkXmlW_Dispose(xmlBody); return; } xml = CkXmlW_Create(); CkXmlW_LoadXml(xml,CkHttpResponseW_bodyStr(resp)); // A successful response should have a 200 response status if (CkHttpResponseW_getStatusCode(resp) != 200) { wprintf(L"%s\n",CkXmlW_getXml(xml)); wprintf(L"Response Status Code: %d\n",CkHttpResponseW_getStatusCode(resp)); wprintf(L"Failed.\n"); CkHttpResponseW_Dispose(resp); CkStringBuilderW_Dispose(sbUrl); CkAuthUtilW_Dispose(authUtil); CkJsonObjectW_Dispose(json); CkHttpW_Dispose(http); CkDateTimeW_Dispose(dtNow); CkXmlW_Dispose(xmlBody); CkXmlW_Dispose(xml); return; } CkHttpResponseW_Dispose(resp); // Show the XML response.. wprintf(L"%s\n",CkXmlW_getXml(xml)); wprintf(L"--\n"); wprintf(L"Success!\n"); CkStringBuilderW_Dispose(sbUrl); CkAuthUtilW_Dispose(authUtil); CkJsonObjectW_Dispose(json); CkHttpW_Dispose(http); CkDateTimeW_Dispose(dtNow); CkXmlW_Dispose(xmlBody); CkXmlW_Dispose(xml); } |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.