Application Example - GetOrderList by ExportState

Code samples provided here are generated by our clients and their developers. ChannelAdvisor cannot provide code for API development purposes.

Our documentation is meant to be the final format to be delivered to our API.

If you want to see other developer's code to execute calls, make a request of them on the ChannelAdvisor Google Forum.

Pulling orders from your ChannelAdvisor account is easy!

Retrieve the orders that have not already been exported by your developer key.  Here's the flow (you can see the details in the C# sample below or download the project files):

1. Define your order criteria, for example Payment Cleared, and Unshipped.

2. Set the orderCriteria's ExportState to NotExported.

3. Set PageNumberFilter to 1

3. Call GetOrderList and process the first page of Orders returned.

4. Once you've imported the orders for the page, call SetOrdersExportStatus to mark them as Exported.

5. Increment PageNumberFilter and go back to step 3. Repeat until 0 orders are returned in the response.

NOTE: Orders marked as exported will not appear in future GetOrderList calls.

NOTE: The Export state is tracked by your developer key.  This means that you will not be affected by another developer's application that is pulling orders from your account (assuming they have security rights to read the same account data as you).  If you have two different applications exporting orders, you can request a second developer key so your two applications don't collide.

The sample below is a C# windows application.

Follow these steps to get it working (this is not meant to be an intro to working with web services in .NET):  Project files are here.

1. Create a C# windows app.  Mine is called sampleExport.

2. Add a web service reference pointing to  .NET will create a web service proxy.  Note that pointing the web reference to the url without ?WSDL at the end will cause the proxy-builder tool to fail.  My proxy's namespace is  You will need to change any references to that namespace in the code to match the namespace for your proxy.  If you accepted the default when you added the web reference, it will most likely be <YourAppName>.com.channeladvisor.api.  Note that this example is using a .NET 2.0-style Web reference, not a service reference, which would produce a very different-looking set of proxy classes.

3. Put your credentials in the variables developerKey, password, and accountID.

4. Orders that are pulled down are just written to the disk, currently to C:\Orders\, and files are named <ClientOrderIdentifier>.xml.  Feel free to change these.

5. Once the complete page of orders is written out, setOrdersExported is called, passing the list of ClientOrderIdentifiers.

6. By setting these as exported, the sample won't retrieve these orders again.

7. Writing the orders to disk could be used as a rudimentary queuing system.  You could use a second application to do something else with them once they exist as files, or you can change the code here to do something more useful, like load them directly into a database.

using System;
using System.Collections.Generic;
using System.Windows.Forms;
using System.Xml;
using System.Xml.Serialization;

using; // this is the .NET generated proxy for ChannelAdvisor web services

namespace sampleExport
   public partial class Form1 : Form
      public Form1()

      private void button1_Click(object sender, EventArgs e)
         string developerKey = string.Empty;
         string password = string.Empty;
         string accountID = string.Empty;

         developerKey = "DevKey";
         password= "SomePassword";
         accountID = "AccountKey";

         OrderCriteria criteria = new OrderCriteria();
         criteria.StatusUpdateFilterBeginTimeGMT = DateTime.UtcNow.AddDays(-30);
         criteria.StatusUpdateFilterEndTimeGMT = DateTime.UtcNow;

         // this would be like a Ready-To-Ship Report
         criteria.PaymentStatusFilter = "Cleared";
         criteria.ShippingStatusFilter = "Unshipped";

         criteria.ExportState = "NotExported";
         criteria.DetailLevel = "Complete";
         criteria.PageSize = 20;

         OrderService orderService = new OrderService();
         orderService.APICredentialsValue = new APICredentials();
         orderService.APICredentialsValue.DeveloperKey = developerKey;
         orderService.APICredentialsValue.Password = password;

            criteria.PageNumberFilter = 1;
               APIResultOfArrayOfOrderResponseItem orderResponse = orderService.GetOrderList(accountID, criteria);

               if (orderResponse.Status == ResultStatus.Failure)
                  throw new Exception(orderResponse.Message);

               if (orderResponse.ResultData.Length == 0)
                  break; // we ran out of pages that have data in them

               List<string> clientOrderIdentifiers = new List<string>();
               XmlSerializer serializer = new XmlSerializer(typeof(OrderResponseDetailComplete));
               XmlTextWriter writer = null;
               foreach(OrderResponseItem order in orderResponse.ResultData)
                  OrderResponseDetailComplete completeOrder = order as OrderResponseDetailComplete;
                  //put the order on the disk as its own file
                  using (writer = new XmlTextWriter(string.Format(@"C:\orders\{0}.xml", completeOrder.ClientOrderIdentifier), System.Text.Encoding.UTF8))
                     serializer.Serialize(writer, completeOrder);
                  //keep the ClientOrderIdentifier so we can send a batch to mark the orders as exported, filtering the orders from future queries

               //submit our batch of processed orders
               APIResultOfArrayOfBoolean exportStatusResponse = orderService.SetOrdersExportStatus(accountID, clientOrderIdentifiers.ToArray(), true);

               if (exportStatusResponse.Status == ResultStatus.Failure)
                  throw new Exception(exportStatusResponse.Message);

               //make sure each order was succesfully updated
               for (int responseCount = 0; responseCount < exportStatusResponse.ResultData.Length; ++responseCount)
                  if (exportStatusResponse.ResultData[responseCount] == false)
                     //order was not successfully marked as exported
                     MessageBox.Show("Order was not successfully marked as exported:" + orderResponse.ResultData[responseCount].ClientOrderIdentifier);
         catch (Exception ex)
         { // big catch for the entire function

The GetOrderList request XML produced by the code above is equivalent to the following:

<soapenv:Envelope xmlns:soapenv=""

Here is a Java implementation generously provided by Materro LLC

import java.util.ArrayList;
import java.util.Calendar;

import org.apache.axis.Handler;
import org.apache.axis.SimpleChain;
import org.apache.axis.SimpleTargetedChain;
import org.apache.axis.client.AxisClient;
import org.apache.axis.configuration.SimpleProvider;
import org.apache.axis.transport.http.HTTPSender;
import org.apache.axis.transport.http.HTTPTransport;

import com.channeladvisor.api.datacontracts.orders.OrderCart;
import com.channeladvisor.api.datacontracts.orders.OrderCriteria;
import com.channeladvisor.api.datacontracts.orders.OrderLineItemInvoice;
import com.channeladvisor.api.datacontracts.orders.OrderLineItemItem;
import com.channeladvisor.api.datacontracts.orders.OrderLineItemPromo;
import com.channeladvisor.api.datacontracts.orders.OrderResponseDetailHigh;
import com.channeladvisor.api.datacontracts.orders.OrderResponseItem;
import com.channeladvisor.api.webservices.APIResultOfArrayOfOrderResponseItem;
import com.channeladvisor.api.webservices.APIResultOfString;
import com.channeladvisor.api.webservices.OrderServiceLocator;
import com.channeladvisor.api.webservices.OrderServiceSoap;
// In Eclipse (Java EE Luna Release), choose File, Other, Web Service Client
// enter,
// raise slider to Test client. Create AuthenticationHandler class per AdminService ping example

public class GetOrderListChannelAdvisor {
   public static void main(String[] args) throws Exception {
      SimpleProvider provider = new SimpleProvider();
      Handler handler = new AuthenticationHandler();
      SimpleChain requestChain = new SimpleChain();
      SimpleChain responseChain = new SimpleChain();
      Handler sender = new HTTPSender();
      Handler transport = new SimpleTargetedChain(requestChain, sender, responseChain);
      provider.deployTransport(HTTPTransport.DEFAULT_TRANSPORT_NAME, transport);
      OrderServiceLocator locator = new OrderServiceLocator();
      locator.setEngine(new AxisClient(provider));
      OrderServiceSoap orderServiceSoap = locator.getOrderServiceSoap();
      OrderCriteria orderCriteria = new OrderCriteria();
      Calendar monthAgo = Calendar.getInstance();
      monthAgo.add(Calendar.DATE, -30);
      int pageNumber = 0;
      ArrayList<String> skuList = new ArrayList<String>();
      boolean moreResults = true;
      while (moreResults) {
// get the Account ID used below from My Account, Account Authorizations
// once the AdminService has been used to authorize the developer permissions
         APIResultOfArrayOfOrderResponseItem orderResponse = orderServiceSoap.getOrderList("xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx", orderCriteria);
         System.out.println("GetOrderList:" + orderResponse.getStatus());
         OrderResponseItem[] orderResponseList = orderResponse .getResultData();
         if (orderResponseList.length == 0 || orderResponseList.length < orderCriteria.getPageSize()) {
            moreResults = false;
         System.out.println("GetOrderList length:" + orderResponseList.length);
         for (int i = 0; i < orderResponseList.length; i++) {
            System.out.println("Client Order Identifier:" + orderResponseList[i].getClientOrderIdentifier());
            System.out.println("Total Order Amount:" + orderResponseList[i].getTotalOrderAmount());
            System.out.println("OrderID = " + orderResponseList[i].getOrderID());
            OrderResponseDetailHigh order = (OrderResponseDetailHigh) orderResponseList[i];
            OrderCart shoppingCart = order.getShoppingCart();
            OrderLineItemItem[] invoiceLine = shoppingCart.getLineItemSKUList();
            for (int j = 0; j < invoiceLine.length; j++) {
               System.out.println("SKU " + (j + 1) + ":" + invoiceLine[j].getSKU());
            OrderLineItemPromo[] promo = shoppingCart.getLineItemPromoList();
            for (int j = 1; j < promo.length; j++) {
               System.out.println("Promo code of " + promo[j].getPromoCode() + " had a value of " + promo[j].getUnitPrice());
            OrderLineItemInvoice[] line = shoppingCart.getLineItemInvoiceList();
            for (int j = 1; j < promo.length; j++) {
               if (line[j].getLineItemType() == "Shipping") {
                  System.out.println("Shipping charge of " + line[j].getUnitPrice());
               } else if (line[j].getLineItemType() == "VATShipping") {
                  System.out.println("VAT Shipping charge of " + line[j].getUnitPrice());
               } else if (line[j].getLineItemType() == "SalesTax") {
                  System.out.println("Sales Tax charge of " + line[j].getUnitPrice());
               } else if (line[j].getLineItemType() == "ShippingInsurance") {
                  System.out.println("Shipping Insurance charge of " + line[j].getUnitPrice());
               } else {
                  System.out.println("Unexpected line type of " + line[j].getUnitPrice());