Pulling orders from your ChannelAdvisor account is easy!
Retrieve the orders that haven't already been exported by your developer Key. Here's the flow (you can see the details in the C# sample below or the attached project files
):
1. Define your order criteria, for example Payment Cleared, and Unshipped.
2. Set the orderCriteria's ExportState to NotExported.
3. Call GetOrderList and process the first page of Orders returned.
4. Once you've imported the orders for the page, call setOrderExportState to mark them as Exported.
5. These orders will now NOT appear when you request page 1 again. *
6. 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.
* When using the ExportState filter in this way, you need to leave orderCriteria.PageNumberFilter = 1. This is because when you mark the order as exported it drops out of the return set, so you actually want to keep pulling page 1 until there are no more records.
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 https://api.channeladvisor.com/ChannelAdvisorAPI/v1/OrderService.asmx?WSDL
. .NET will create a web service proxy. Note that pointing the web reference to the url without the ?WSDL at the end will cause the proxy builder tool to fail. My proxy's namespace is sampleExport.com.channeladvisor.qa._0002.api. 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
3. Put your credentials in the variables devkey, pwd, and acct.
4. Orders that are pulled down are just written to the disk, currently to C:\Orders\, and files are named <OrderNumber>.xml. Feel free to change these.
5. Once the complete page of orders is written out, setOrdersExported is called, passing the list of orderNumbers.
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 queueing 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.
//these are standard namespaces that come with a Windows app in C#
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
//adding these namespaces for CA functionality
using sampleExport.com.channeladvisor.qa._0002.api; // this is the .NET generated proxy for CA web services
using System.Xml.Serialization; //to write the Order to the disk
using System.Xml; //to write the Order to the disk
using System.IO; //to write the Order to the disk
namespace sampleExport
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void button1_Click(object sender, EventArgs e)
{
string url = "https://api.channeladvisor.com/ChannelAdvisorAPI/v1/OrderService.asmx";
string devkey = string.Empty;
string pwd = string.Empty;
string acct = string.Empty;
devkey = "DevKey";
pwd= "SomePassword";
acct = "AccountKey";
OrderCriteria oc = new OrderCriteria() ;
//go back 21 days to make sure we get all orders not exported yet
oc.StatusUpdateFilterBeginTimeGMT = DateTime.UtcNow.AddDays(-30);
oc.StatusUpdateFilterEndTimeGMT = DateTime.UtcNow;
oc.PaymentStatusFilter = PaymentStatusCode.Cleared;
oc.ExportStateSpecified = true; //WSDL released 5/2008 requires this from .NET if using an ExportState value
oc.ExportState = ExportStateType.NotExported ;
oc.DetailLevel = DetailLevelType.Complete ;
oc.PageSize = 20;
OrderService ws = new OrderService();
ws.Url = url;
ws.APICredentialsValue = new APICredentials();
ws.APICredentialsValue.DeveloperKey = devkey;
ws.APICredentialsValue.Password = pwd;
//for testing this can mark certain as NotExported
//string[] ar = new string[3];
//ar[0] = "1234564";
//ar[1] = "4844565";
//ar[2] = "7432454";
//ws.SetOrdersExportStatus(acct, ar, false);
try
{
int i = 1;
do
{
oc.PageNumberFilter = i;
APIResultOfArrayOfOrderResponseItem resp = ws.GetOrderList(acct, oc);
OrderResponseItem[] items = resp.ResultData;
if (items.Length == 0) break; // we moved outside the pages that have data on them
//MessageBox.Show(items.Length.ToString());
string[] ids = new string[items.Length];
System.Xml.Serialization.XmlSerializer ser = new XmlSerializer(typeof(OrderResponseItem));
System.Xml.XmlTextWriter write;
for (int orderCount = 0; orderCount < items.Length; orderCount++)
{
OrderResponseItem item = items[orderCount];
//put the order on the disk as its own file
write = new XmlTextWriter(string.Format(@"C:\orders\{0}.xml", item.ClientOrderIdentifier), System.Text.Encoding.UTF8);
ser.Serialize(write, item);
write.Close();
//hold the OrderNumber so we can send a batch to mark them as Exported so we don't get them again
ids[orderCount] = item.ClientOrderIdentifier;
}
//submit our batch of processed orders
APIResultOfArrayOfBoolean b = ws.SetOrdersExportStatus(acct, ids, true);
//make sure each order was succesfully updated
bool[] arBool = b.ResultData;
for (int responseCount = 0; responseCount < arBool.Length; responseCount++)
{
if (arBool[responseCount] == false)
{
//order was not successfully marked as exported
MessageBox.Show("Order was not successfully marked as Exported:" + items[responseCount].ClientOrderIdentifier);
}
}
} while (true);
}
catch (Exception ex)
{ // big catch for the entire function
MessageBox.Show(ex.ToString());
}
}
}
}
}
What happens if someone reopens the checkout (for example to split the order) after an order has been tagged as "Exported"? This is quite common and it appears that our downstream system would simply miss the change to the order in this case.
Ian Slinger
Right, you will not get updates if you mark it as exported, so you should mark orders exported when you aren't interested in any changes made in the CA order. We have designed the Export feature to support a query of ChangedSinceLastExport, but that has not been created yet.
How do I apply this example into my PHP code?
How do I apply this example into my old ASP code?
You'll need to understand how to access SOAP web services from asp. Try googling it for articles. I found this which looks pretty good: http://www.devarticles.com/c/a/ASP/An-Introduction-To-XML-SOAP-Using-ASP-and-VB6/![]()
Once you get a reference to the web service in vb6, you should be able to follow along in the text at the top of the page and the code insert.
Hi there - is this now live (says it was released Saturday)? Thanks