Skip to main content
Published: August 16 2010, 1:56:00 PMUpdated: November 28 2020, 8:40:58 PM

This sample demonstrates how to go about Sales order processing using GetOrders with order creation time filter described in the KB Order management using Trading API - GetOrders. The sample has been written in VB.NET using .NET SDK v817.


Below is the code. Corresponding GetOrders SOAP request is attached with this article.

© 2010-2013 eBay Inc., All Rights Reserved
'Licensed under CDDL 1.0 -

Imports eBay.Service.Call
Imports eBay.Service.Core.Sdk
Imports eBay.Service.Util
Imports eBay.Service.Core.Soap

Namespace Trading_Samples
     Public Class OrderManagement
          Private Sub GetOrders()
               'create the context
               Dim context As New ApiContext()

               'set the User token
               context.ApiCredential.eBayToken = "Your token"

               'set the server url
               context.SoapApiServerUrl = ""

               'enable logging
               context.ApiLogManager = New ApiLogManager()
               context.ApiLogManager.ApiLoggerList.Add(New FileLogger("log.txt", True, True, True))
               context.ApiLogManager.EnableLogging = True

               'set the version
               context.Version = "817"
               context.Site = SiteCodeType.UK
               Dim blnHasMore As Boolean = True

               Dim CreateTimeFromPrev As DateTime, CreateTimeFrom As DateTime, CreateTimeTo As DateTime

               Dim getOrders__1 As New GetOrdersCall(context)
               getOrders__1.DetailLevelList = New DetailLevelCodeTypeCollection()

               'CreateTimeTo set to the current time
               CreateTimeTo = DateTime.Now.ToUniversalTime()

               'Assumption call is made every 15 sec. So CreateTimeFrom of last call was 15 mins
               'prior to now
               Dim ts1 As New TimeSpan(9000000000L)
               CreateTimeFromPrev = CreateTimeTo.Subtract(ts1)

               'Set the CreateTimeFrom the last time you made the call minus 2 minutes
               Dim ts2 As New TimeSpan(1200000000)
               CreateTimeFrom = CreateTimeFromPrev.Subtract(ts2)

               getOrders__1.CreateTimeFrom = CreateTimeFrom
               getOrders__1.CreateTimeTo = CreateTimeTo


               If getOrders__1.ApiResponse.Ack <> AckCodeType.Failure Then
                    'Check if any orders are returned
                    If getOrders__1.ApiResponse.OrderArray.Count <> 0 Then
                         For Each order As OrderType In getOrders__1.ApiResponse.OrderArray
                              'Update your system with the order information.
                              Console.WriteLine("Order Number: " + order.OrderID)
                              Console.WriteLine("OrderStatus: " + order.OrderStatus)
                              Console.WriteLine("Order Created On: " + order.CreatedTime)

                              'Get Order Details
                              Dim orderTrans As TransactionTypeCollection = order.TransactionArray

                              'Order could be comprised of one or more items
                              For Each transaction As TransactionType In orderTrans
                                   Console.WriteLine((("Order for: " + transaction.Item.ItemID & ", ") + transaction.Item.SKU & ", ") + transaction.Item.Title)

                                   'If you are listing variation items, you will need to retrieve the variation
                                   'details as chosen by the buyer
                                   If transaction.Variation.SKU IsNot Nothing Then
                                        Console.WriteLine("Variation: " + transaction.Variation.SKU)
                                   End If
                                   Console.WriteLine("OrderLineItemID: " + transaction.OrderLineItemID)
                                   Console.WriteLine("Qty Purchased: " + transaction.QuantityPurchased)

                                   Console.WriteLine(("Buyer Info: " + order.BuyerUserID & ", ") + transaction.Buyer.Email)

                              If order.CheckoutStatus.Status = CompleteStatusCodeType.Complete Then
                                   'Get Payment Details
                                   Console.WriteLine("Order Adjustment Amount: " + order.AdjustmentAmount.Value)
                                   Console.WriteLine("Order Amount Paid: " + order.AmountPaid.Value)
                                   Console.WriteLine("Payment Method: " + order.CheckoutStatus.PaymentMethod)

                                   Dim extTrans As ExternalTransactionTypeCollection = order.ExternalTransaction

                                   For Each extTran As ExternalTransactionType In extTrans
                                        Console.WriteLine("External TransactionID: " + extTran.ExternalTransactionID)
                                        Console.WriteLine("External Transaction Time: " + extTran.ExternalTransactionTime)
                                        Console.WriteLine("Payment/Refund Amount: " + extTran.PaymentOrRefundAmount.Value)

                                   'Get shipping information
                                   Dim shipping As ShippingServiceOptionsType
                                   shipping = order.ShippingServiceSelected

                                   Console.WriteLine("Shipping Service Selected: " + order.ShippingServiceSelected.ShippingService)

                                   'Get Shipping Address - Address subject to change if the buyer has not completed checkout                      
                                   Dim address As AddressType = order.ShippingAddress

                                   Dim sAdd As New StringBuilder()
                                   sAdd = sAdd.Append(address.Name)
                                   If address.Street IsNot Nothing AndAlso address.Street <> "" Then
                                        sAdd.Append(", " + address.Street)
                                   End If
                                   If address.Street1 IsNot Nothing AndAlso address.Street1 <> "" Then
                                        sAdd.Append(", " + address.Street1)
                                   End If
                                   If address.Street2 IsNot Nothing AndAlso address.Street2 <> "" Then
                                        sAdd.Append(", " + address.Street2)
                                   End If
                                   If address.CityName IsNot Nothing AndAlso address.CityName <> "" Then
                                        sAdd.Append(", " + address.CityName)
                                   End If
                                   If address.StateOrProvince IsNot Nothing AndAlso address.StateOrProvince <> "" Then
                                        sAdd.Append(", " + address.StateOrProvince)
                                   End If
                                   If address.PostalCode IsNot Nothing AndAlso address.PostalCode <> "" Then
                                        sAdd.Append(", " + address.PostalCode)
                                   End If
                                   If address.CountryName IsNot Nothing AndAlso address.CountryName <> "" Then
                                        sAdd.Append(", " + address.CountryName)
                                   End If
                                   If address.Phone IsNot Nothing AndAlso address.Phone <> "" Then
                                        sAdd.Append(": Phone" + address.Phone)
                                   End If

                                   Console.WriteLine("Shipping Address: " & sAdd)

                                   Dim salesTax As Double
                                   'Get the sales tax
                                   If order.ShippingDetails.SalesTax.SalesTaxAmount Is Nothing Then
                                        salesTax = 0.0
                                        salesTax = order.ShippingDetails.SalesTax.SalesTaxAmount.Value
                                   End If

                                   Console.WriteLine("Sales Tax: " & salesTax)

                                   If order.BuyerCheckoutMessage IsNot Nothing Then
                                        Console.WriteLine("Buyer Checkout Message: " + order.BuyerCheckoutMessage)

                                   End If
                              End If
                    End If
               End If

          End Sub
     End Class
End Namespace

How well did this answer your question?
Answers others found helpful