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
(PureBasic) Walmart - Get an Order by purchaseOrderIdGets the XML data for an order by purchaseOrderId.
IncludeFile "CkXml.pb" IncludeFile "CkHttp.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkAuthUtil.pb" IncludeFile "CkJsonObject.pb" Procedure ChilkatExample() ; --------------------------------------------------------------------------------------------------------- ; 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. ; 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.i = CkStringBuilder::ckCreate() If sbUrl.i = 0 Debug "Failed to create object." ProcedureReturn EndIf success.i = CkStringBuilder::ckAppend(sbUrl,"https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}") numReplaced.i = CkStringBuilder::ckReplace(sbUrl,"{purchaseOrderId}","1111691995111") requestMethod.s = "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.i = CkAuthUtil::ckCreate() If authUtil.i = 0 Debug "Failed to create object." ProcedureReturn EndIf wmConsumerId.s = "WALMART_CONSUMER_ID" wmPrivateKey.s = "WALMART_PRIVATE_KEY" jsonStr.s = CkAuthUtil::ckWalmartSignature(authUtil,CkStringBuilder::ckGetAsString(sbUrl),wmConsumerId,wmPrivateKey,requestMethod) If CkAuthUtil::ckLastMethodSuccess(authUtil) <> 1 Debug CkAuthUtil::ckLastErrorText(authUtil) CkStringBuilder::ckDispose(sbUrl) CkAuthUtil::ckDispose(authUtil) ProcedureReturn EndIf ; 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.i = CkJsonObject::ckCreate() If json.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkJsonObject::ckLoad(json,jsonStr) http.i = CkHttp::ckCreate() If http.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkHttp::ckSetRequestHeader(http,"WM_SVC.NAME","Walmart Marketplace") CkHttp::ckSetRequestHeader(http,"WM_QOS.CORRELATION_ID",CkJsonObject::ckStringOf(json,"correlation_id")) CkHttp::ckSetRequestHeader(http,"WM_SEC.TIMESTAMP",CkJsonObject::ckStringOf(json,"timestamp")) CkHttp::ckSetRequestHeader(http,"WM_SEC.AUTH_SIGNATURE",CkJsonObject::ckStringOf(json,"signature")) CkHttp::ckSetRequestHeader(http,"WM_CONSUMER.ID",wmConsumerId) CkHttp::ckSetRequestHeader(http,"WM_CONSUMER.CHANNEL.TYPE","WALMART_CHANNEL_TYPE") CkHttp::setCkAccept(http, "application/xml") ; Note: Do not explicitly set the "Host" header. Chilkat will set it automatically. xmlStr.s = CkHttp::ckQuickGetStr(http,CkStringBuilder::ckGetAsString(sbUrl)) If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkStringBuilder::ckDispose(sbUrl) CkAuthUtil::ckDispose(authUtil) CkJsonObject::ckDispose(json) CkHttp::ckDispose(http) ProcedureReturn EndIf xml.i = CkXml::ckCreate() If xml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::ckLoadXml(xml,xmlStr) ; A successful response should have a 200 response status If CkHttp::ckLastStatus(http) <> 200 Debug CkXml::ckGetXml(xml) Debug "Response Status Code: " + Str(CkHttp::ckLastStatus(http)) Debug "Failed." CkStringBuilder::ckDispose(sbUrl) CkAuthUtil::ckDispose(authUtil) CkJsonObject::ckDispose(json) CkHttp::ckDispose(http) CkXml::ckDispose(xml) ProcedureReturn EndIf ; Show the XML response: Debug CkXml::ckGetXml(xml) Debug "Success." CkStringBuilder::ckDispose(sbUrl) CkAuthUtil::ckDispose(authUtil) CkJsonObject::ckDispose(json) CkHttp::ckDispose(http) CkXml::ckDispose(xml) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.