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
(DataFlex) Walmart - Get List of OrdersDemonstrates how to get a list of all orders.
Use ChilkatAx-win32.pkg Procedure Test Handle hoSbUrl Boolean iSuccess Integer iNumReplaced Handle hoDtStartDate String sRequestMethod Handle hoAuthUtil String sWmConsumerId String sWmPrivateKey String sJsonStr Handle hoJson Handle hoHttp String sXmlStr Handle hoXml Integer i Integer iNumOrders Variant vOrder Handle hoOrder Integer j Integer iNumOrderLines Variant vOrderLine Handle hoOrderLine Integer k Integer iNumOrderLineStatuses String sTemp1 Integer iTemp1 Boolean bTemp1 // --------------------------------------------------------------------------------------------------------- // 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 a list of Walmart orders and parse the XML result. // --- // Note: The Walmart documentation indicates that the createdStartDate/createdEndDate query parameters are optional, // however, this may not actually be the case. It may be that at least one is required for getting a list of orders. // --- // The general format to get orders is as follows: // GET https://marketplace.walmartapis.com/v3/orders?sku={sku}&customerOrderId={customerOrderId}&purchaseOrderId={purchaseOrderId}&status={status}&createdStartDate={createdStartDate}&createdEndDate={createdEndDate}&fromExpectedShipDate={fromExpectedShipDate}&toExpectedShipDate={toExpectedShipDate}&limit={limit} // Let's build a request to get all the orders in the last 7 days. Get Create (RefClass(cComChilkatStringBuilder)) To hoSbUrl If (Not(IsComObjectCreated(hoSbUrl))) Begin Send CreateComObject of hoSbUrl End Get ComAppend Of hoSbUrl "https://marketplace.walmartapis.com/v3/orders?createdStartDate={createdStartDate}&limit={limit}" To iSuccess // We'll just get 2 results so we can demonstrate iterating over the XML.. Get ComReplaceI Of hoSbUrl "{limit}" 2 To iNumReplaced // Get the current system date/time and add -7 days to get 1 week ago. Get Create (RefClass(cComCkDateTime)) To hoDtStartDate If (Not(IsComObjectCreated(hoDtStartDate))) Begin Send CreateComObject of hoDtStartDate End Get ComSetFromCurrentSystemTime Of hoDtStartDate To iSuccess Get ComAddDays Of hoDtStartDate -7 To iSuccess Get ComGetAsTimestamp Of hoDtStartDate False To sTemp1 Showln "One week ago (GMT): " sTemp1 Get ComGetAsTimestamp Of hoDtStartDate False To sTemp1 Get ComReplace Of hoSbUrl "{createdStartDate}" sTemp1 To iNumReplaced Move "GET" To sRequestMethod // First we need to generate a signature for our request. // The signature needs to be re-generated for each new Walmart HTTP request. Get Create (RefClass(cComChilkatAuthUtil)) To hoAuthUtil If (Not(IsComObjectCreated(hoAuthUtil))) Begin Send CreateComObject of hoAuthUtil End Move "WALMART_CONSUMER_ID" To sWmConsumerId Move "WALMART_PRIVATE_KEY" To sWmPrivateKey Get ComGetAsString Of hoSbUrl To sTemp1 Get ComWalmartSignature Of hoAuthUtil sTemp1 sWmConsumerId sWmPrivateKey sRequestMethod To sJsonStr Get ComLastMethodSuccess Of hoAuthUtil To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoAuthUtil To sTemp1 Showln sTemp1 Procedure_Return End // 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 Get Create (RefClass(cComChilkatJsonObject)) To hoJson If (Not(IsComObjectCreated(hoJson))) Begin Send CreateComObject of hoJson End Get ComLoad Of hoJson sJsonStr To iSuccess Get Create (RefClass(cComChilkatHttp)) To hoHttp If (Not(IsComObjectCreated(hoHttp))) Begin Send CreateComObject of hoHttp End Send ComSetRequestHeader To hoHttp "WM_SVC.NAME" "Walmart Marketplace" Get ComStringOf Of hoJson "correlation_id" To sTemp1 Send ComSetRequestHeader To hoHttp "WM_QOS.CORRELATION_ID" sTemp1 Get ComStringOf Of hoJson "timestamp" To sTemp1 Send ComSetRequestHeader To hoHttp "WM_SEC.TIMESTAMP" sTemp1 Get ComStringOf Of hoJson "signature" To sTemp1 Send ComSetRequestHeader To hoHttp "WM_SEC.AUTH_SIGNATURE" sTemp1 Send ComSetRequestHeader To hoHttp "WM_CONSUMER.ID" sWmConsumerId // Note: check to see what keyword you should use for your situation. // The keyword "WALMART_CHANNEL_TYPE" is one option. Another is "SWAGGER_CHANNEL_TYPE". Send ComSetRequestHeader To hoHttp "WM_CONSUMER.CHANNEL.TYPE" "WALMART_CHANNEL_TYPE" Set ComAccept Of hoHttp To "application/xml" // Note: Do not explicitly set the "Host" header. Chilkat will set it automatically. Get ComGetAsString Of hoSbUrl To sTemp1 Get ComQuickGetStr Of hoHttp sTemp1 To sXmlStr Get ComLastMethodSuccess Of hoHttp To bTemp1 If (bTemp1 <> True) Begin Get ComLastErrorText Of hoHttp To sTemp1 Showln sTemp1 Procedure_Return End Get Create (RefClass(cComChilkatXml)) To hoXml If (Not(IsComObjectCreated(hoXml))) Begin Send CreateComObject of hoXml End Get ComLoadXml Of hoXml sXmlStr To iSuccess // A successful response should have a 200 response status Get ComLastStatus Of hoHttp To iTemp1 If (iTemp1 <> 200) Begin Get ComGetXml Of hoXml To sTemp1 Showln sTemp1 Get ComLastStatus Of hoHttp To iTemp1 Showln "Response Status Code: " iTemp1 Showln "Failed." Procedure_Return End // A sample XML response is shown below.. // Let's grab some information, and iterate over the XML.. Get ComGetChildIntValue Of hoXml "ns3:meta|ns3:totalCount" To iTemp1 Showln "Total number of orders in last 7 days: " iTemp1 // The outermost loop loops over the orders. // The next inner loop loops over the order lines. // The innermost loop loops over the order line statuses. Move 0 To i Get ComNumChildrenAt Of hoXml "ns3:elements" To iNumOrders While (i < iNumOrders) Set ComI Of hoXml To i Showln "---- order " (i + 1) " ----" Get ComGetChildWithTag Of hoXml "ns3:elements|ns3:order[i]" To vOrder If (IsComObject(vOrder)) Begin Get Create (RefClass(cComChilkatXml)) To hoOrder Set pvComObject Of hoOrder To vOrder End Get ComGetChildContent Of hoOrder "ns3:purchaseOrderId" To sTemp1 Showln "purchaseOrderId: " sTemp1 Get ComGetChildContent Of hoOrder "ns3:shippingInfo|ns3:postalAddress|ns3:name" To sTemp1 Showln "name: " sTemp1 Move 0 To j Get ComNumChildrenAt Of hoOrder "ns3:orderLines" To iNumOrderLines While (j < iNumOrderLines) Set ComJ Of hoOrder To j Get ComGetChildWithTag Of hoOrder "ns3:orderLines|ns3:orderLine[j]" To vOrderLine If (IsComObject(vOrderLine)) Begin Get Create (RefClass(cComChilkatXml)) To hoOrderLine Set pvComObject Of hoOrderLine To vOrderLine End Get ComGetChildContent Of hoOrderLine "ns3:item|ns3:productName" To sTemp1 Showln " productName: " sTemp1 Move 0 To k Get ComNumChildrenAt Of hoOrderLine "ns3:orderLineStatuses" To iNumOrderLineStatuses While (k < iNumOrderLineStatuses) Set ComK Of hoOrderLine To k Get ComGetChildContent Of hoOrderLine "ns3:orderLineStatuses|ns3:orderLineStatus[k]|ns3:status" To sTemp1 Showln " order line status: " sTemp1 Get ComGetChildContent Of hoOrderLine "ns3:orderLineStatuses|ns3:orderLineStatus[k]|ns3:trackingInfo|ns3:carrierName|ns3:carrier" To sTemp1 Showln " order line carrier: " sTemp1 Move (k + 1) To k Loop Send Destroy of hoOrderLine Move (j + 1) To j Loop Send Destroy of hoOrder Move (i + 1) To i Loop Showln "Success." // --------------------------------------- // Sample XML response // (The confidential information has been redacted or modified with fake data. // --------------------------------------- // <?xml version="1.0" encoding="UTF-8" standalone="yes" ?> // <ns3:list xmlns:ns2="http://walmart.com/mp/orders" xmlns:ns3="http://walmart.com/mp/v3/orders" xmlns:ns4="http://walmart.com/"> // <ns3:meta> // <ns3:totalCount>239</ns3:totalCount> // <ns3:limit>2</ns3:limit> // <ns3:nextCursor>?limit=2&hasMoreElements=true&soIndex=239&poIndex=1578652999055&partnerId=10000999999&sellerId=9999&createdStartDate=2017-04-21T19:08:55Z&createdEndDate=2017-04-28T19:08:58.464Z</ns3:nextCursor> // </ns3:meta> // <ns3:elements> // <ns3:order> // <ns3:purchaseOrderId>1111641944111</ns3:purchaseOrderId> // <ns3:customerOrderId>1111777852111</ns3:customerOrderId> // <ns3:customerEmailId>somebody@somewhere.com</ns3:customerEmailId> // <ns3:orderDate>2017-04-21T01:25:52.000Z</ns3:orderDate> // <ns3:shippingInfo> // <ns3:phone>3175555555</ns3:phone> // <ns3:estimatedDeliveryDate>2017-05-10T06:00:00.000Z</ns3:estimatedDeliveryDate> // <ns3:estimatedShipDate>2017-04-29T06:00:00.000Z</ns3:estimatedShipDate> // <ns3:methodCode>Value</ns3:methodCode> // <ns3:postalAddress> // <ns3:name>barry redacted</ns3:name> // <ns3:address1>9999 redacted dr</ns3:address1> // <ns3:city>Indianapolis</ns3:city> // <ns3:state>IN</ns3:state> // <ns3:postalCode>46227</ns3:postalCode> // <ns3:country>USA</ns3:country> // <ns3:addressType>RESIDENTIAL</ns3:addressType> // </ns3:postalAddress> // </ns3:shippingInfo> // <ns3:orderLines> // <ns3:orderLine> // <ns3:lineNumber>1</ns3:lineNumber> // <ns3:item> // <ns3:productName>DPX DPx HEST 2.0 Mil-Spec Fixed Blade G10 Multi-Colored</ns3:productName> // <ns3:sku>DPXG~DPHSX008~00317</ns3:sku> // </ns3:item> // <ns3:charges> // <ns3:charge> // <ns3:chargeType>PRODUCT</ns3:chargeType> // <ns3:chargeName>ItemPrice</ns3:chargeName> // <ns3:chargeAmount> // <ns3:currency>USD</ns3:currency> // <ns3:amount>125.00</ns3:amount> // </ns3:chargeAmount> // </ns3:charge> // </ns3:charges> // <ns3:orderLineQuantity> // <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement> // <ns3:amount>1</ns3:amount> // </ns3:orderLineQuantity> // <ns3:statusDate>2017-04-28T18:09:26.000Z</ns3:statusDate> // <ns3:orderLineStatuses> // <ns3:orderLineStatus> // <ns3:status>Shipped</ns3:status> // <ns3:statusQuantity> // <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement> // <ns3:amount>1</ns3:amount> // </ns3:statusQuantity> // <ns3:trackingInfo> // <ns3:shipDateTime>2017-04-24T20:57:52.000Z</ns3:shipDateTime> // <ns3:carrierName> // <ns3:carrier>USPS</ns3:carrier> // </ns3:carrierName> // <ns3:methodCode>Value</ns3:methodCode> // <ns3:trackingNumber>redacted</ns3:trackingNumber> // <ns3:trackingURL>http://walmart.narvar.com/walmart/tracking/usps?redacted</ns3:trackingURL> // </ns3:trackingInfo> // </ns3:orderLineStatus> // </ns3:orderLineStatuses> // </ns3:orderLine> // </ns3:orderLines> // </ns3:order> // <ns3:order> // <ns3:purchaseOrderId>1111652066111</ns3:purchaseOrderId> // <ns3:customerOrderId>1111778837111</ns3:customerOrderId> // <ns3:customerEmailId>somebody2@somewhere.com</ns3:customerEmailId> // <ns3:orderDate>2017-04-22T13:37:12.000Z</ns3:orderDate> // <ns3:shippingInfo> // <ns3:phone>8435555555</ns3:phone> // <ns3:estimatedDeliveryDate>2017-05-11T06:00:00.000Z</ns3:estimatedDeliveryDate> // <ns3:estimatedShipDate>2017-05-02T06:00:00.000Z</ns3:estimatedShipDate> // <ns3:methodCode>Value</ns3:methodCode> // <ns3:postalAddress> // <ns3:name>Doug Redacted</ns3:name> // <ns3:address1>1111 redacted dr</ns3:address1> // <ns3:city>Columbia</ns3:city> // <ns3:state>SC</ns3:state> // <ns3:postalCode>29527</ns3:postalCode> // <ns3:country>USA</ns3:country> // <ns3:addressType>RESIDENTIAL</ns3:addressType> // </ns3:postalAddress> // </ns3:shippingInfo> // <ns3:orderLines> // <ns3:orderLine> // <ns3:lineNumber>1</ns3:lineNumber> // <ns3:item> // <ns3:productName>Rayovac Specialty Battery 123A 2PK, RL123A-2D</ns3:productName> // <ns3:sku>RAYO~RL123A-2A~46270</ns3:sku> // </ns3:item> // <ns3:charges> // <ns3:charge> // <ns3:chargeType>PRODUCT</ns3:chargeType> // <ns3:chargeName>ItemPrice</ns3:chargeName> // <ns3:chargeAmount> // <ns3:currency>USD</ns3:currency> // <ns3:amount>12.92</ns3:amount> // </ns3:chargeAmount> // </ns3:charge> // </ns3:charges> // <ns3:orderLineQuantity> // <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement> // <ns3:amount>1</ns3:amount> // </ns3:orderLineQuantity> // <ns3:statusDate>2017-04-28T17:18:51.000Z</ns3:statusDate> // <ns3:orderLineStatuses> // <ns3:orderLineStatus> // <ns3:status>Shipped</ns3:status> // <ns3:statusQuantity> // <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement> // <ns3:amount>1</ns3:amount> // </ns3:statusQuantity> // <ns3:trackingInfo> // <ns3:shipDateTime>2017-04-28T16:50:53.000Z</ns3:shipDateTime> // <ns3:carrierName> // <ns3:carrier>USPS</ns3:carrier> // </ns3:carrierName> // <ns3:methodCode>Value</ns3:methodCode> // <ns3:trackingNumber>redacted</ns3:trackingNumber> // <ns3:trackingURL>http://walmart.narvar.com/walmart/tracking/usps?redacted</ns3:trackingURL> // </ns3:trackingInfo> // </ns3:orderLineStatus> // </ns3:orderLineStatuses> // </ns3:orderLine> // <ns3:orderLine> // <ns3:lineNumber>2</ns3:lineNumber> // <ns3:item> // <ns3:productName>Rayovac Specialty Battery 123A 2PK, RL123A-2D</ns3:productName> // <ns3:sku>RAYO~RL123A-2A~46270</ns3:sku> // </ns3:item> // <ns3:charges> // <ns3:charge> // <ns3:chargeType>PRODUCT</ns3:chargeType> // <ns3:chargeName>ItemPrice</ns3:chargeName> // <ns3:chargeAmount> // <ns3:currency>USD</ns3:currency> // <ns3:amount>12.92</ns3:amount> // </ns3:chargeAmount> // </ns3:charge> // </ns3:charges> // <ns3:orderLineQuantity> // <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement> // <ns3:amount>1</ns3:amount> // </ns3:orderLineQuantity> // <ns3:statusDate>2017-04-28T17:18:51.000Z</ns3:statusDate> // <ns3:orderLineStatuses> // <ns3:orderLineStatus> // <ns3:status>Shipped</ns3:status> // <ns3:statusQuantity> // <ns3:unitOfMeasurement>EACH</ns3:unitOfMeasurement> // <ns3:amount>1</ns3:amount> // </ns3:statusQuantity> // <ns3:trackingInfo> // <ns3:shipDateTime>2017-04-28T16:50:53.000Z</ns3:shipDateTime> // <ns3:carrierName> // <ns3:carrier>USPS</ns3:carrier> // </ns3:carrierName> // <ns3:methodCode>Value</ns3:methodCode> // <ns3:trackingNumber>redacted</ns3:trackingNumber> // <ns3:trackingURL>http://walmart.narvar.com/walmart/tracking/usps?redacted</ns3:trackingURL> // </ns3:trackingInfo> // </ns3:orderLineStatus> // </ns3:orderLineStatuses> // </ns3:orderLine> // </ns3:orderLines> // </ns3:order> // </ns3:elements> // </ns3:list> End_Procedure |
© 2000-2024 Chilkat Software, Inc. All Rights Reserved.