C# Examples

The examples on this page use a .NET 4.5 client library. The source code and dlls are provided by the links below.

Product Requests

var productApi = new ProductAPI();
var product = productApi.GetProductBySku("10006");
var product2 = productApi.GetProductByUpc("782631003079");
var product3 = productApi.GetProductByManufacturerNumber("0307");
var price = productApi.GetDiscountedPrice("10006");
//Loop through all product pages
var products = new List<Product>();
var pageNumber = 1;
var totalPages = 1;
do
{
	var results = productApi.GetProducts(pageNumber, 100, excludeDiscounted: true);
	totalPages = results.TotalPages;
	products.AddRange(results.Products);
	Console.WriteLine("{0} page(s) of {1} total loaded", pageNumber, totalPages);
	pageNumber++;
} while (totalPages >= pageNumber);

Inventory Requests

var inventoryApi = new InventoryAPI();
var inventory = inventoryApi.GetInventoryBySku("10006");
var inventory2 = inventoryApi.GetInventoryByUpc("782631003079");
//Loop through all inventory pages
var inventoryList = new List<Inventory>();
var pageNumber = 1;
var totalPages = 1;
do
{
	var results = inventoryApi.GetInventory(pageNumber, 1000);
	totalPages = results.TotalPages;
	inventoryList.AddRange(results.Inventories);
	Console.WriteLine("{0} page(s) of {1} total loaded", pageNumber, totalPages);
	pageNumber++;
} while (totalPages >= pageNumber);

Carrier Requests

var carrierApi = new CarrierAPI();
var carriers = carrierApi.GetCarriers();
var id = carriers.Carriers.First().Id;
var carrier = carrierApi.GetCarrierById(id);

Order Status Requests

var orderStatusApi = new OrderStatusAPI();
var results = orderStatusApi.GetOrderStatuses();
var firstResult = results.OrderStatuses.FirstOrDefault();
if (firstResult == null)
	return;
var orderStatus = orderStatusApi.GetOrderStatusByOrderNumber(firstResult.OrderNumber);
var orderStatus2 = orderStatusApi.GetOrderStatusByPoNumber(firstResult.PoNumber);
var package = firstResult.Packages.FirstOrDefault(p => !string.IsNullOrWhiteSpace(p.TrackingNumber));
if (package == null)
	return;
var trackingNumber = package.TrackingNumber;
if (string.IsNullOrWhiteSpace(trackingNumber))
	return;
var orderStatus3 = orderStatusApi.GetOrderStatusByTrackingNumber(trackingNumber);

Order Requests

 //Get all orders
var results = orderApi.GetOrders();
var firstResult = results.Orders.FirstOrDefault();
if (firstResult == null)
	return;
//Various ways to get a specific order
var order = orderApi.GetOrdersByOrderNumber(firstResult.OrderNumber);
var order2 = orderApi.GetOrdersByExternalOrderNumber(firstResult.ExternalOrderNumber);
var order3 = orderApi.GetOrdersByPoNumber(firstResult.PoNumber);
var firstPackage = firstResult.Packages.FirstOrDefault();
if (firstPackage == null)
	return;
var order4 = orderApi.GetOrdersByTrackingNumber(firstPackage.TrackingNumber);

Create Order

//Create new order example
var orderApi = new OrderAPI();
var createOrderObject = new CreateOrderRequest
{
	ExternalOrderNumber = "1234",
	PoNumber = "myPoNo",
	DeliveryInstructions = "Test order",
	OrderDate = DateTime.Now,
	ShippingOptionId = 128082,
	ShippingAddress = new Address
	{
		Name = "Test User",
		Address1 = "123 Main",
		Address2 = "Apt 1123",
		Address3 = "Buiding 4",
		City = "Miami",
		State = "MI",
		Country = "USA",
		ZipCode = "90210"
	},
	CreateOrderRequestLines = new CreateOrderRequestLine[] {
		new CreateOrderRequestLine
		{
			Sku = "10006",
			Quantity = 1
		}
	}
};
var response = orderApi.CreateOrder(createOrderObject);