Chilkat Examples

ChilkatHOMEAndroid™Classic ASPCC++C#Mono C#.NET Core C#C# UWP/WinRTDataFlexDelphi ActiveXDelphi DLLVisual FoxProJavaLianjaMFCObjective-CPerlPHP ActiveXPHP ExtensionPowerBuilderPowerShellPureBasicCkPythonChilkat2-PythonRubySQL ServerSwift 2Swift 3/4TclUnicode CUnicode C++Visual Basic 6.0VB.NETVB.NET UWP/WinRTVBScriptXojo PluginNode.jsExcelGo

SQL Server Web API Examples

Primary Categories

AWS Translate
Activix CRM
Adyen
Amazon MWS
Azure Maps
Azure Monitor
Azure OAuth2
Azure Storage Accounts
Bluzone
CardConnect
ClickBank
Clickatell
Cloudfare
DocuSign
ETrade
Etsy
Facebook
GeoOp
GetHarvest
Jira
MYOB

Magento
Microsoft Calendar
Microsoft Group
Microsoft Tasks and Plans
Okta OAuth/OIDC
OneLogin OIDC
PayPal
Peoplevox
Populi
QuickBooks
SOAP finkok.com
Shippo
Shopify
Stripe
SugarCRM
Trello
Twitter
VoiceBase
Vonage
Walmart
Walmart v3
Xero
eBay
effectconnect

 

 

 

(SQL Server) Walmart - Get List of Orders

Demonstrates how to get a list of all orders.

Note: This example requires Chilkat v9.5.0.67 or greater.

Chilkat ActiveX Downloads

ActiveX for 32-bit and 64-bit Windows

CREATE PROCEDURE ChilkatSample
AS
BEGIN
    DECLARE @hr int
    DECLARE @iTmp0 int
    DECLARE @sTmp0 nvarchar(4000)
    -- 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.
    DECLARE @sbUrl int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.StringBuilder', @sbUrl OUT
    IF @hr <> 0
    BEGIN
        PRINT 'Failed to create ActiveX component'
        RETURN
    END

    DECLARE @success int
    EXEC sp_OAMethod @sbUrl, 'Append', @success OUT, 'https://marketplace.walmartapis.com/v3/orders?createdStartDate={createdStartDate}&limit={limit}'
    -- We'll just get 2 results so we can demonstrate iterating over the XML..
    DECLARE @numReplaced int
    EXEC sp_OAMethod @sbUrl, 'ReplaceI', @numReplaced OUT, '{limit}', 2

    -- Get the current system date/time and add -7 days to get 1 week ago.
    DECLARE @dtStartDate int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.CkDateTime', @dtStartDate OUT

    EXEC sp_OAMethod @dtStartDate, 'SetFromCurrentSystemTime', @success OUT
    EXEC sp_OAMethod @dtStartDate, 'AddDays', @success OUT, -7

    EXEC sp_OAMethod @dtStartDate, 'GetAsTimestamp', @sTmp0 OUT, 0
    PRINT 'One week ago (GMT): ' + @sTmp0

    EXEC sp_OAMethod @dtStartDate, 'GetAsTimestamp', @sTmp0 OUT, 0
    EXEC sp_OAMethod @sbUrl, 'Replace', @numReplaced OUT, '{createdStartDate}', @sTmp0

    DECLARE @requestMethod nvarchar(4000)
    SELECT @requestMethod = 'GET'

    -- First we need to generate a signature for our request.
    -- The signature needs to be re-generated for each new Walmart HTTP request.
    DECLARE @authUtil int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.AuthUtil', @authUtil OUT

    DECLARE @wmConsumerId nvarchar(4000)
    SELECT @wmConsumerId = 'WALMART_CONSUMER_ID'
    DECLARE @wmPrivateKey nvarchar(4000)
    SELECT @wmPrivateKey = 'WALMART_PRIVATE_KEY'
    DECLARE @jsonStr nvarchar(4000)
    EXEC sp_OAMethod @sbUrl, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @authUtil, 'WalmartSignature', @jsonStr OUT, @sTmp0, @wmConsumerId, @wmPrivateKey, @requestMethod
    EXEC sp_OAGetProperty @authUtil, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN
        EXEC sp_OAGetProperty @authUtil, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @sbUrl
        EXEC @hr = sp_OADestroy @dtStartDate
        EXEC @hr = sp_OADestroy @authUtil
        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
    DECLARE @json int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.JsonObject', @json OUT

    EXEC sp_OAMethod @json, 'Load', @success OUT, @jsonStr

    DECLARE @http int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Http', @http OUT

    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'WM_SVC.NAME', 'Walmart Marketplace'
    EXEC sp_OAMethod @json, 'StringOf', @sTmp0 OUT, 'correlation_id'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'WM_QOS.CORRELATION_ID', @sTmp0
    EXEC sp_OAMethod @json, 'StringOf', @sTmp0 OUT, 'timestamp'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'WM_SEC.TIMESTAMP', @sTmp0
    EXEC sp_OAMethod @json, 'StringOf', @sTmp0 OUT, 'signature'
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'WM_SEC.AUTH_SIGNATURE', @sTmp0
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'WM_CONSUMER.ID', @wmConsumerId
    -- 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".
    EXEC sp_OAMethod @http, 'SetRequestHeader', NULL, 'WM_CONSUMER.CHANNEL.TYPE', 'WALMART_CHANNEL_TYPE'

    EXEC sp_OASetProperty @http, 'Accept', 'application/xml'

    -- Note: Do not explicitly set the "Host" header.  Chilkat will set it automatically.

    DECLARE @xmlStr nvarchar(4000)
    EXEC sp_OAMethod @sbUrl, 'GetAsString', @sTmp0 OUT
    EXEC sp_OAMethod @http, 'QuickGetStr', @xmlStr OUT, @sTmp0
    EXEC sp_OAGetProperty @http, 'LastMethodSuccess', @iTmp0 OUT
    IF @iTmp0 <> 1
      BEGIN
        EXEC sp_OAGetProperty @http, 'LastErrorText', @sTmp0 OUT
        PRINT @sTmp0
        EXEC @hr = sp_OADestroy @sbUrl
        EXEC @hr = sp_OADestroy @dtStartDate
        EXEC @hr = sp_OADestroy @authUtil
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @http
        RETURN
      END

    DECLARE @xml int
    EXEC @hr = sp_OACreate 'Chilkat_9_5_0.Xml', @xml OUT

    EXEC sp_OAMethod @xml, 'LoadXml', @success OUT, @xmlStr

    -- A successful response should have a 200 response status
    EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT
    IF @iTmp0 <> 200
      BEGIN
        EXEC sp_OAMethod @xml, 'GetXml', @sTmp0 OUT
        PRINT @sTmp0

        EXEC sp_OAGetProperty @http, 'LastStatus', @iTmp0 OUT
        PRINT 'Response Status Code: ' + @iTmp0

        PRINT 'Failed.'
        EXEC @hr = sp_OADestroy @sbUrl
        EXEC @hr = sp_OADestroy @dtStartDate
        EXEC @hr = sp_OADestroy @authUtil
        EXEC @hr = sp_OADestroy @json
        EXEC @hr = sp_OADestroy @http
        EXEC @hr = sp_OADestroy @xml
        RETURN
      END

    -- A sample XML response is shown below..

    -- Let's grab some information, and iterate over the XML..

    EXEC sp_OAMethod @xml, 'GetChildIntValue', @iTmp0 OUT, 'ns3:meta|ns3:totalCount'
    PRINT 'Total number of orders in last 7 days: ' + @iTmp0

    -- 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.
    DECLARE @i int
    SELECT @i = 0
    DECLARE @numOrders int
    EXEC sp_OAMethod @xml, 'NumChildrenAt', @numOrders OUT, 'ns3:elements'
    WHILE @i < @numOrders
      BEGIN
        EXEC sp_OASetProperty @xml, 'I', @i


        PRINT '---- order ' + @i + 1 + ' ----'

        DECLARE @order int
        EXEC sp_OAMethod @xml, 'GetChildWithTag', @order OUT, 'ns3:elements|ns3:order[i]'

        EXEC sp_OAMethod @order, 'GetChildContent', @sTmp0 OUT, 'ns3:purchaseOrderId'
        PRINT 'purchaseOrderId: ' + @sTmp0

        EXEC sp_OAMethod @order, 'GetChildContent', @sTmp0 OUT, 'ns3:shippingInfo|ns3:postalAddress|ns3:name'
        PRINT 'name: ' + @sTmp0

        DECLARE @j int
        SELECT @j = 0
        DECLARE @numOrderLines int
        EXEC sp_OAMethod @order, 'NumChildrenAt', @numOrderLines OUT, 'ns3:orderLines'
        WHILE @j < @numOrderLines
          BEGIN
            EXEC sp_OASetProperty @order, 'J', @j
            DECLARE @orderLine int
            EXEC sp_OAMethod @order, 'GetChildWithTag', @orderLine OUT, 'ns3:orderLines|ns3:orderLine[j]'

            EXEC sp_OAMethod @orderLine, 'GetChildContent', @sTmp0 OUT, 'ns3:item|ns3:productName'
            PRINT '  productName: ' + @sTmp0

            DECLARE @k int
            SELECT @k = 0
            DECLARE @numOrderLineStatuses int
            EXEC sp_OAMethod @orderLine, 'NumChildrenAt', @numOrderLineStatuses OUT, 'ns3:orderLineStatuses'
            WHILE @k < @numOrderLineStatuses
              BEGIN
                EXEC sp_OASetProperty @orderLine, 'K', @k

                EXEC sp_OAMethod @orderLine, 'GetChildContent', @sTmp0 OUT, 'ns3:orderLineStatuses|ns3:orderLineStatus[k]|ns3:status'
                PRINT '    order line status: ' + @sTmp0

                EXEC sp_OAMethod @orderLine, 'GetChildContent', @sTmp0 OUT, 'ns3:orderLineStatuses|ns3:orderLineStatus[k]|ns3:trackingInfo|ns3:carrierName|ns3:carrier'
                PRINT '    order line carrier: ' + @sTmp0
                SELECT @k = @k + 1
              END

            EXEC @hr = sp_OADestroy @orderLine

            SELECT @j = @j + 1
          END
        EXEC @hr = sp_OADestroy @order

        SELECT @i = @i + 1
      END


    PRINT '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&amp;hasMoreElements=true&amp;soIndex=239&amp;poIndex=1578652999055&amp;partnerId=10000999999&amp;sellerId=9999&amp;createdStartDate=2017-04-21T19:08:55Z&amp;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>

    EXEC @hr = sp_OADestroy @sbUrl
    EXEC @hr = sp_OADestroy @dtStartDate
    EXEC @hr = sp_OADestroy @authUtil
    EXEC @hr = sp_OADestroy @json
    EXEC @hr = sp_OADestroy @http
    EXEC @hr = sp_OADestroy @xml


END
GO

 

© 2000-2019 Chilkat Software, Inc. All Rights Reserved.