C# SDK Sample: Downloading Orders

This tutorial will download a range of orders in a particular stage for a date range.  You can adjust the order query and expansion parameters to modify the orders you retrieve and how much information is contained within the order.

Download Orders Example
using System;
using com.ultracart.admin.v2.Api;
using com.ultracart.admin.v2.Client;
using com.ultracart.admin.v2.Model;

namespace ConsoleApplication1
{
    class Program
    {
        static void Main(string[] args)
        {
            const string simpleKey = "YOUR API KEY HERE"; // TODO: Replace this with your API Key
            Configuration.Default.ApiKey.Add("x-ultracart-simple-key", simpleKey);

            // This is required.  Search for 'Versioning' on this page:
            // https://www.ultracart.com/api/#topics.html
            Configuration.Default.DefaultHeader.Add("X-UltraCart-Api-Version", "2017-03-01");

            GetOrders();

            Console.Out.WriteLine("DONE - Hit ENTER to exit");
            Console.In.ReadLine();
        }

        static void GetOrders()
        {
            var api = new OrderApi();
            string expand = "summary"; // TODO: Adjust this expansion string to obtain the desired level of detail on your order
            int limit = 100;
            int counter = 1;

            OrderQuery orderQuery = new OrderQuery();

            orderQuery.PaymentDateBegin = "2019-01-01T00:00:00.0000000-05:00";
            orderQuery.PaymentDateEnd = "2019-09-05T00:00:00.0000000-04:00";
            orderQuery.CurrentStage = OrderQuery.CurrentStageEnum.CompletedOrder;

            OrdersResponse res = null;
            do
            {
                if (res == null)
                {
                    res = api.GetOrdersByQuery(orderQuery, limit, 0, null, expand);
                }
                else {
                    res = api.GetOrdersByQuery(orderQuery, limit, res.Metadata.ResultSet.NextOffset, null, expand);
                }

                Console.Out.WriteLine("res.Orders.length = " + res.Orders.Count);

                foreach (var i in res.Orders)
                {
                    Console.Out.WriteLine((counter++) + " " + i.OrderId + " status=" + i.CurrentStage);
                }
            }
            while (res.Metadata.ResultSet.More ?? false);
        }
    }
}