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 - Send Shipping NotificationSee Shipping notifications/updates for more information about this call. Note: This example requires Chilkat v9.5.0.67 or greater.
IncludeFile "CkJsonObject.pb" IncludeFile "CkDateTime.pb" IncludeFile "CkHttp.pb" IncludeFile "CkXml.pb" IncludeFile "CkAuthUtil.pb" IncludeFile "CkStringBuilder.pb" IncludeFile "CkHttpResponse.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. ; Sends the following POST request: ; POST https://marketplace.walmartapis.com/v3/orders/{purchaseOrderId}/shipping 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}/shipping") numReplaced.i = CkStringBuilder::ckReplace(sbUrl,"{purchaseOrderId}","1111691995111") requestMethod.s = "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.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. ; 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.i = 1 shippingStatus.s = "Shipped" quantity.i = 1 carrier.s = "USPS" shippingMethod.s = "Standard" trackingNumber.s = "9999869903501929298999" dtNow.i = CkDateTime::ckCreate() If dtNow.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkDateTime::ckSetFromCurrentSystemTime(dtNow) shipDateTime.s = CkDateTime::ckGetAsTimestamp(dtNow,0) xmlBody.i = CkXml::ckCreate() If xmlBody.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::setCkTag(xmlBody, "ns2:orderShipment") CkXml::ckAddAttribute(xmlBody,"xmlns:ns2","http://walmart.com/mp/v3/orders") CkXml::ckAddAttribute(xmlBody,"xmlns:ns3","http://walmart.com/") CkXml::ckUpdateChildContentInt(xmlBody,"ns2:orderLines|ns2:orderLine|ns2:lineNumber",lineNumber) orderLine.i = CkXml::ckGetChildWithTag(xmlBody,"ns2:orderLines|ns2:orderLine") CkXml::ckUpdateChildContent(orderLine,"ns2:orderLineStatuses|ns2:orderLineStatus|ns2:status",shippingStatus) CkXml::ckDispose(orderLine) orderLineStatus.i = CkXml::ckGetChildWithTag(orderLine,"ns2:orderLineStatuses|ns2:orderLineStatus") CkXml::ckUpdateChildContent(orderLineStatus,"ns2:statusQuantity|ns2:unitOfMeasurement","Each") CkXml::ckUpdateChildContentInt(orderLineStatus,"ns2:statusQuantity|ns2:amount",quantity) CkXml::ckUpdateChildContent(orderLineStatus,"ns2:trackingInfo|ns2:shipDateTime",shipDateTime) CkXml::ckUpdateChildContent(orderLineStatus,"ns2:trackingInfo|ns2:carrierName|ns2:carrier",carrier) CkXml::ckUpdateChildContent(orderLineStatus,"ns2:trackingInfo|ns2:methodCode",shippingMethod) CkXml::ckUpdateChildContent(orderLineStatus,"ns2:trackingInfo|ns2:trackingNumber",trackingNumber) CkXml::ckDispose(orderLineStatus) Debug "POST request body:" Debug CkXml::ckGetXml(xmlBody) Debug "--" ; 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. CkHttp::ckSetRequestHeader(http,"Content-Type","application/xml") resp.i = CkHttp::ckPostXml(http,CkStringBuilder::ckGetAsString(sbUrl),CkXml::ckGetXml(xmlBody),"utf-8") If CkHttp::ckLastMethodSuccess(http) <> 1 Debug CkHttp::ckLastErrorText(http) CkStringBuilder::ckDispose(sbUrl) CkAuthUtil::ckDispose(authUtil) CkJsonObject::ckDispose(json) CkHttp::ckDispose(http) CkDateTime::ckDispose(dtNow) CkXml::ckDispose(xmlBody) ProcedureReturn EndIf xml.i = CkXml::ckCreate() If xml.i = 0 Debug "Failed to create object." ProcedureReturn EndIf CkXml::ckLoadXml(xml,CkHttpResponse::ckBodyStr(resp)) ; A successful response should have a 200 response status If CkHttpResponse::ckStatusCode(resp) <> 200 Debug CkXml::ckGetXml(xml) Debug "Response Status Code: " + Str(CkHttpResponse::ckStatusCode(resp)) Debug "Failed." CkHttpResponse::ckDispose(resp) CkStringBuilder::ckDispose(sbUrl) CkAuthUtil::ckDispose(authUtil) CkJsonObject::ckDispose(json) CkHttp::ckDispose(http) CkDateTime::ckDispose(dtNow) CkXml::ckDispose(xmlBody) CkXml::ckDispose(xml) ProcedureReturn EndIf CkHttpResponse::ckDispose(resp) ; Show the XML response.. Debug CkXml::ckGetXml(xml) Debug "--" Debug "Success!" CkStringBuilder::ckDispose(sbUrl) CkAuthUtil::ckDispose(authUtil) CkJsonObject::ckDispose(json) CkHttp::ckDispose(http) CkDateTime::ckDispose(dtNow) CkXml::ckDispose(xmlBody) CkXml::ckDispose(xml) ProcedureReturn EndProcedure |
© 2000-2025 Chilkat Software, Inc. All Rights Reserved.