Dashboard > ChannelAdvisor Developer Network > ... > Code Samples > OrderService.GetOrderList Visual Studio.Net Example
Log In   View a printable version of the current page.
OrderService.GetOrderList Visual Studio.Net Example
Added by Greg Smith, last edited by Greg Smith on Oct 25, 2007  (view change)
Labels: 
(None)


Here's a C# sample that pulls shipped orders for a certain date range.

 
private void button1_Click(object sender, EventArgs e)
{
	WindowsApplication13.
OrderRetriever getOrders = new OrderRetriever();

	List<string> genString = getOrders.GetSkuList();

	MessageBox.Show(genString.Count.ToString());

}
using System;
using System.Collections.Generic;
using System.Text;
namespace WindowsApplication13
{
public class OrderRetriever
{
public List<string> GetSkuList()
{
//
// 1. For this sample to work you will need create a web reference in
// your VS.Net project by pointing to this URL:
// https://api.channeladvisor.com/ChannelAdvisorAPI/v1/InventoryService.asmx
// Accept the default reference name of com.channeladvisor.api.OrderService
//
// 2. You will most likely need to change the namespace above (WindowsApplication13) to match
// your projects default namespace so that it can see the web reference.
// 3. Update the code to use your DeveloperKey, password, and AccountKey.

const string developerApiGuid = "MyDeveloperKey";
const string password = "myPassword";
const string sellerAccountGuid = "MyAccountKey";
com.channeladvisor.api.OrderService orderService = new com.channeladvisor.api.OrderService();
com.channeladvisor.api.APICredentials apiCredentials = new com.channeladvisor.api.APICredentials();
apiCredentials.DeveloperKey = developerApiGuid;
apiCredentials.Password = password;
orderService.APICredentialsValue = apiCredentials;
com.channeladvisor.api.OrderCriteria orderCriteria = new com.channeladvisor.api.OrderCriteria();
// Only grab items that are marked has Shipped
orderCriteria.ShippingStatusFilter = com.channeladvisor.api.ShippingStatusCode.Shipped;
//Only grab orders created between Oct 8, 2007 to Oct 12, 2007
orderCriteria.OrderCreationFilterBeginTimeGMT = new System.DateTime(2007, 10, 11);
orderCriteria.OrderCreationFilterEndTimeGMT = new DateTime(2007, 10, 12);
// Set other properties required by call
orderCriteria.DetailLevel = com.channeladvisor.api.DetailLevelType.High;
orderCriteria.PageSize = 50; // Show 50 orders per page
orderCriteria.PageNumberFilter = 0;
List<string> skuList = new List<string>();
bool moreResults = true;
// Call the API several times to retrieve a list of all matches
while (moreResults)
{
    orderCriteria.PageNumberFilter += 1; // Get the next page each time through the loop
    com.channeladvisor.api.APIResultOfArrayOfOrderResponseItem orderResponse = orderService.GetOrderList(sellerAccountGuid, orderCriteria);
    if (orderResponse.Status == com.channeladvisor.api.ResultStatus.Success)
    {
       com.channeladvisor.api.OrderResponseItem[] orderResponseList = orderResponse.ResultData;
       if (orderResponseList.Length == 0 || orderResponseList.Length < orderCriteria.PageSize)
       {
       moreResults = false;
       }
       //step through each order in our returned array
       foreach (com.channeladvisor.api.OrderResponseDetailHigh order in orderResponseList)
       {
       System.Diagnostics.Debug.WriteLine("OrderID= " + order.OrderID.ToString());
       //step through each item in this Order
       foreach (com.channeladvisor.api.OrderLineItemItem invoiceLine in order.ShoppingCart.LineItemSKUList)
       {
             System.Diagnostics.Debug.WriteLine("OrderID= " + invoiceLine.LineItemID.ToString() );
            // Grab a list of all SKUs from invoices on this page
            skuList.Add(invoiceLine.SKU);
       }
       
       //step through each Promo.  
       foreach (com.channeladvisor.api.OrderLineItemPromo promo in order.ShoppingCart.LineItemPromoList)
       {
              System.Diagnostics.Debug.WriteLine(string.Format("Promo code of {0} had a value of {1}", promo.PromoCode, promo.UnitPrice));
       }

       //step through each ItemInvoice in this Order.  These are similar to subtotal categories
       foreach (com.channeladvisor.api.OrderLineItemInvoice line in order.ShoppingCart.LineItemInvoiceList)
       {
        if (line.LineItemType == com.channeladvisor.api.LineItemTypeCode.Shipping)
        {
           System.Diagnostics.Debug.WriteLine(string.Format("Shipping charge of {0}",line.UnitPrice));
        }
        else if (line.LineItemType == com.channeladvisor.api.LineItemTypeCode.VATShipping)
        {
           System.Diagnostics.Debug.WriteLine(string.Format("VATShipping charge of {0}", line.UnitPrice));

        }
        else if (line.LineItemType == com.channeladvisor.api.LineItemTypeCode.SalesTax)
        {
            System.Diagnostics.Debug.WriteLine(string.Format("Order's SalesTax is {0}", line.UnitPrice));

        }
        else if (line.LineItemType == com.channeladvisor.api.LineItemTypeCode.ShippingInsurance)
        {
             System.Diagnostics.Debug.WriteLine(string.Format("Shipping Insurance charge of {0}", line.UnitPrice));
        }
        else 
             System.Diagnostics.Debug.WriteLine("Unexpected line type of " + line.LineItemType.ToString());// = .line.UnitPrice);
                            
       }
     }
}
else
{
       int errorCode = orderResponse.MessageCode;
       string errorMessage = orderResponse.Message;
       System.Diagnostics.Debug.WriteLine(string.Format("An unexpected error occured.&nbsp; ErrorCode={0}, ErrorMessage={1}", errorCode, errorMessage));
       //throw new System.Exception(string.Format("An unexpected error occured.&nbsp; ErrorCode={0}, ErrorMessage={1}", errorCode, errorMessage));
}
}
return skuList;
}
}
}
Powered by Atlassian Confluence, the Enterprise Wiki. (Version: 2.5.1 Build:#806 May 06, 2007) - Bug/feature request - Contact Administrators